Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: added cmdlets to easily enable/disable telemetry #2432

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
## [Current Nightly]

### Added

- Added `-DisableGridEditing` option to `Set-PnPList` which allows gridview editing to be enabled or disabled on a list [#2188](https://github.com/pnp/powershell/pull/2188)
- Added verbose logging for `Invoke-PnPSiteSwap`, `Restore-PnPTenantSite` and cmdlets which depend on `SpoOperation`. [#2207](https://github.com/pnp/powershell/pull/2207)
- Added support for `DisplayNamesOfFileViewers` and `DisplayNamesOfFileViewersInSpo` properties in `Get-PnPTenant` and `Set-PnPTenant` cmdlets to show/hide viewers in property pane for a file. [#2271](https://github.com/pnp/powershell/pull/2271)
Expand All @@ -32,8 +33,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `Get-PnPTeamsTag` cmdlet to retrieve Team tags information. [#2414](https://github.com/pnp/powershell/pull/2414)
- Added `Set-PnPTeamsTag` cmdlet to update Team tags information. [#2419](https://github.com/pnp/powershell/pull/2419)
- Added `Remove-PnPTeamsTag` cmdlet to delete a Team tag. [#2419](https://github.com/pnp/powershell/pull/2419)
- Added `Disable-PnPPowerShellTelemetry` cmdlet to disable telemetry collection. [#2432](https://github.com/pnp/powershell/pull/2432)
- Added `Enable-PnPPowerShellTelemetry` cmdlet to enable telemetry collection. [#2432](https://github.com/pnp/powershell/pull/2432)

### Changed

- Changed to no longer require `https://` to be prefixed when using `Connect-PnPOnline -Url tenant.sharepoint.com` [#2139](https://github.com/pnp/powershell/pull/2139)
- `Get-PnPAvailableSensitivityLabel` cmdlet now uses the non-deprecated Graph API to retrieve sensitivity label. [#2234](https://github.com/pnp/powershell/pull/2234)
- Improved `Get-PnPMicrosoft365Group` cmdlet to better check the Id, DisplayName and MailNickname of Microsoft 365 Group. [#2258](https://github.com/pnp/powershell/pull/2258)
Expand All @@ -47,10 +51,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Changed the Microsoft 365 Groups cmdlets to use the `v1.0` endpoint instead of the `beta` [#2426](https://github.com/pnp/powershell/pull/2426)

### Removed

- Marked `-Resource` parameter from `Get-PnPAccessToken` cmdlet as obsolete as it was not used anymore anyway. It will be removed in a future version. [#2182](https://github.com/pnp/powershell/pull/2182)
- Removed `-SystemUpdate` option from `Set-PnPListItem` as it has been deprecated two years ago. Use `-UpdateType SystemUpdate` instead [#2396](https://github.com/pnp/powershell/pull/2396)

### Fixed

- Fixed issue where passing in `-Connection` to `Disconnect-PnPOnline` would throw an exception [#2093](https://github.com/pnp/powershell/pull/2093)
- Fixed `Get-PnPSiteSearchQueryResults` throwing `Value cannot be null` exception [#2138](https://github.com/pnp/powershell/pull/2138)
- Fixed `New-PnPUPABulkImportJob` not returing the job Id [#2144](https://github.com/pnp/powershell/pull/2144)
Expand All @@ -68,6 +74,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed issue with `Set-PnPTeamsChannel -IsFavoriteByDefault` throwing a `Nullable object must have a value` under certain circumstances [#2425](https://github.com/pnp/powershell/pull/2425)

### Contributors

- Rob Lempens [RobLempens]
- Marc Studer [Studermarc]
- Giacomo Pozzoni [jackpoz]
Expand Down Expand Up @@ -131,7 +138,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `Add-PnPListItemAttachment` cmdlet to provide ability to upload a file as an attachment to a SharePoint list item. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Remove-PnPListItemAttachment` cmdlet to provide ability to delete a list item attachment. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `Get-PnPListItemAttachment` cmdlet to download the attachments from a list item. [#1932](https://github.com/pnp/powershell/pull/1932)
- Added `-ReturnTyped` parameter to `Get-PnPField` cmdlet so that it returns specific type instead of the generic field type. [#1888] (https://github.com/pnp/powershell/pull/1888)
- Added `-ReturnTyped` parameter to `Get-PnPField` cmdlet so that it returns specific type instead of the generic field type. [#1888](https://github.com/pnp/powershell/pull/1888)
- Added `Add-PnPViewsFromXML` cmdlet to create one or more views in a list based on an XML string. [#1963](https://github.com/pnp/powershell/pull/1963)
- Added `-ExemptFromBlockDownloadOfNonViewableFiles` parameter to `Set-PnPList` cmdlet to configure access capabilites for unmanaged devices at list level. [#1973](https://github.com/pnp/powershell/pull/1973)
- Added `-PercentComplete`, `-Priority`, `-StartDateTime`, `-DueDateTime` and `-Description` to `Add-PnPPlannerTask` [#1964](https://github.com/pnp/powershell/pull/1964)
Expand All @@ -157,7 +164,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Changed

- Changed `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` to map users based on their Ids instead which should resolve some issues around user identities reporting not to exist. You can use the new `-IdType` option to switch it back to `PrincipalName` if needed. [#1752](https://github.com/pnp/powershell/pull/1752)
- Changed `Add-PnPField` now returns specific type taxonomy field type instead of the generic type. [#1888] (https://github.com/pnp/powershell/pull/1888)
- Changed `Add-PnPField` now returns specific type taxonomy field type instead of the generic type. [#1888](https://github.com/pnp/powershell/pull/1888)
- Changed `Get-PnPOrgAssetsLibrary` to return a proper value of the organisation assets libraries. [#1889](https://github.com/pnp/powershell/pull/1889)
- Bumped .NET Framework version to 4.6.2 as the 4.6.1 is not supported anymore. [#1856](https://github.com/pnp/powershell/pull/1856)
- Changed `Add-PnPDataRowsToSiteTemplate`, it will now export a datetime field value as UTC string. [#1900](https://github.com/pnp/powershell/pull/1900)
Expand Down
63 changes: 63 additions & 0 deletions documentation/Disable-PnPPowerShellTelemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
Module Name: PnP.PowerShell
title: Disable-PnPPowerShellTelemetry
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Disable-PnPPowerShellTelemetry.html
---

# Disable-PnPPowerShellTelemetry

## SYNOPSIS
Disables sending of telemetry data.

## SYNTAX

### Disable sending of telemetry data after going through a confirmation question.

```powershell
Disable-PnPPowerShellTelemetry
```

### Disable sending of telemetry data skipping the confirmation question.

```powershell
Disable-PnPPowerShellTelemetry -Force
```
## DESCRIPTION

This cmdlet disables sending of telemetry data.

## EXAMPLES

### EXAMPLE 1
```powershell
Disable-PnPPowerShellTelemetry
```

Disables sending to telemetry data after answering the confirmation question.

### EXAMPLE 2
```powershell
Disable-PnPPowerShellTelemetry -Force
```

Disables sending to telemetry data skipping the confirmation question.
## PARAMETERS
### -Force
Switch parameter which executes the cmdlet and skips the confirmation question.

```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
63 changes: 63 additions & 0 deletions documentation/Enable-PnPPowerShellTelemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
Module Name: PnP.PowerShell
title: Enable-PnPPowerShellTelemetry
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Enable-PnPPowerShellTelemetry.html
---

# Enable-PnPPowerShellTelemetry

## SYNOPSIS
Enables sending of telemetry data.

## SYNTAX

### Enable sending of telemetry data after going through a confirmation question.

```powershell
Enable-PnPPowerShellTelemetry
```

### Enable sending of telemetry data skipping the confirmation question.

```powershell
Enable-PnPPowerShellTelemetry -Force
```
## DESCRIPTION

This cmdlet Enables sending of telemetry data.

## EXAMPLES

### EXAMPLE 1
```powershell
Enable-PnPPowerShellTelemetry
```

Enables sending of telemetry data after answering the confirmation question.

### EXAMPLE 2
```powershell
Enable-PnPPowerShellTelemetry -Force
```

Enables sending of telemetry data skipping the confirmation question.
## PARAMETERS
### -Force
Switch parameter which executes the cmdlet and skips the confirmation question.

```yaml
Type: SwitchParameter
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
2 changes: 1 addition & 1 deletion src/Commands/Admin/RemoveTenantDeletedSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void ExecuteCmdlet()
}
else
{
if (Force || ShouldContinue($"Remove site collection {Identity.Url}?", "Confirm"))
if (Force || ShouldContinue($"Remove site collection {Identity.Url}?", Properties.Resources.Confirm))
{
SpoOperation spoOperation = Tenant.RemoveDeletedSite(Identity.Url);
ClientContext.Load(spoOperation);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Admin/RestoreTenantSite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected override void ExecuteCmdlet()
}
else
{
if (Force || ShouldContinue($"Restore site collection {Identity.Url}?", "Confirm"))
if (Force || ShouldContinue($"Restore site collection {Identity.Url}?", Properties.Resources.Confirm))
{
WriteVerbose($"Restoring site collection {Identity.Url}");

Expand Down
14 changes: 7 additions & 7 deletions src/Commands/Admin/SetTenant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected override void ExecuteCmdlet()
Tenant.ProvisionSharedWithEveryoneFolder = ProvisionSharedWithEveryoneFolder.Value;
modified = true;
}
if (SignInAccelerationDomain != null && (Force || ShouldContinue($@"Please confirm that ""{SignInAccelerationDomain}"" is correct, and you have federated sign-in configured for that domain. Otherwise, your users will no longer be able to sign in. Do you want to continue?", "Confirm")))
if (SignInAccelerationDomain != null && (Force || ShouldContinue($@"Please confirm that ""{SignInAccelerationDomain}"" is correct, and you have federated sign-in configured for that domain. Otherwise, your users will no longer be able to sign in. Do you want to continue?", Properties.Resources.Confirm)))
{
Tenant.SignInAccelerationDomain = SignInAccelerationDomain;
modified = true;
Expand All @@ -358,7 +358,7 @@ protected override void ExecuteCmdlet()
{
throw new InvalidOperationException("This setting cannot be changed until you set the SignInAcceleration Domain.");
}
if (Force || ShouldContinue("Make sure that your federated sign-in supports guest users. If it doesn’t, your guest users will no longer be able to sign in after you set EnableGuestSignInAcceleration to $true.", "Confirm"))
if (Force || ShouldContinue("Make sure that your federated sign-in supports guest users. If it doesn’t, your guest users will no longer be able to sign in after you set EnableGuestSignInAcceleration to $true.", Properties.Resources.Confirm))
{
Tenant.EnableGuestSignInAcceleration = EnableGuestSignInAcceleration.Value;
modified = true;
Expand All @@ -376,7 +376,7 @@ protected override void ExecuteCmdlet()
Tenant.UsePersistentCookiesForExplorerView = UsePersistentCookiesForExplorerView.Value;
modified = true;
}
if (BccExternalSharingInvitations.HasValue && (!BccExternalSharingInvitations.Value || (BccExternalSharingInvitations.Value && (Force || ShouldContinue("The recipients listed in BccExternalSharingInvitationsList will be blind copied on all external sharing invitations. Do you want to continue?", "Confirm")))))
if (BccExternalSharingInvitations.HasValue && (!BccExternalSharingInvitations.Value || (BccExternalSharingInvitations.Value && (Force || ShouldContinue("The recipients listed in BccExternalSharingInvitationsList will be blind copied on all external sharing invitations. Do you want to continue?", Properties.Resources.Confirm)))))
{
Tenant.BccExternalSharingInvitations = BccExternalSharingInvitations.Value;
modified = true;
Expand Down Expand Up @@ -485,7 +485,7 @@ protected override void ExecuteCmdlet()
{
throw new ArgumentException("OrphanedPersonalSitesRetentionPeriod must have a value between 30 and 3650");
}
if (Force || ShouldContinue("This will update the Retention Policy for All Orphaned OneDrive for Business sites.", "Confirm"))
if (Force || ShouldContinue("This will update the Retention Policy for All Orphaned OneDrive for Business sites.", Properties.Resources.Confirm))
{
try
{
Expand Down Expand Up @@ -548,7 +548,7 @@ protected override void ExecuteCmdlet()
if (OneDriveForGuestsEnabled.HasValue)
{
string message = OneDriveForGuestsEnabled.Value ? "This will enable all users, including guests, to create OneDrive for Business sites. You must first assign OneDrive for Business licenses to the guests before they can create their OneDrive for Business sites." : "Guests will no longer be able to create new OneDrive for Business sites. Existing sites won’t be impacted.";
if (Force || ShouldContinue(message, "Confirm"))
if (Force || ShouldContinue(message, Properties.Resources.Confirm))
{
Tenant.OneDriveForGuestsEnabled = OneDriveForGuestsEnabled.Value;
modified = true;
Expand Down Expand Up @@ -738,7 +738,7 @@ protected override void ExecuteCmdlet()
WriteWarning("Users will not be able to download files that can't be viewed on the web. To allow download of files that can't be viewed on the web, run the cmdlet again and set AllowDownloadingNonWebViewableFiles to true.");
}
}
else if (Force || ShouldContinue("To set this parameter, you need to set the Set-PnPTenant -ConditionalAccessPolicy to AllowLimitedAccess. Would you like to set it now?", "Confirm"))
else if (Force || ShouldContinue("To set this parameter, you need to set the Set-PnPTenant -ConditionalAccessPolicy to AllowLimitedAccess. Would you like to set it now?", Properties.Resources.Confirm))
{
Tenant.ConditionalAccessPolicy = SPOConditionalAccessPolicyType.AllowLimitedAccess;
Tenant.AllowDownloadingNonWebViewableFiles = AllowDownloadingNonWebViewableFiles.Value;
Expand All @@ -764,7 +764,7 @@ protected override void ExecuteCmdlet()
Tenant.AllowEditing = AllowEditing.Value;
modified = true;
}
else if (Force || ShouldContinue("To set this parameter, you need to set the Set-PnPTenant -ConditionalAccessPolicy to AllowLimitedAccess. Would you like to set it now?", "Confirm"))
else if (Force || ShouldContinue("To set this parameter, you need to set the Set-PnPTenant -ConditionalAccessPolicy to AllowLimitedAccess. Would you like to set it now?", Properties.Resources.Confirm))
{
Tenant.ConditionalAccessPolicy = SPOConditionalAccessPolicyType.AllowLimitedAccess;
Tenant.AllowEditing = AllowEditing.Value;
Expand Down
39 changes: 39 additions & 0 deletions src/Commands/Base/DisablePowerShellTelemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

namespace PnP.PowerShell.Commands.Base
{
[Cmdlet(VerbsLifecycle.Disable, "PnPPowerShellTelemetry")]
public class DisablePowerShellTelemetry : PnPSharePointCmdlet
{
[Parameter(Mandatory = false)]
public SwitchParameter Force;

protected override void ProcessRecord()
{
var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var telemetryFile = System.IO.Path.Combine(userFolder, ".pnppowershelltelemetry");
if (Force || ShouldContinue("Do you want to disable telemetry for PnP PowerShell?", Properties.Resources.Confirm))
{
System.IO.File.WriteAllText(telemetryFile, "disallow");
Environment.SetEnvironmentVariable("PNPPOWERSHELL_DISABLETELEMETRY", "true");
if (Connection != null)
{
Connection.ApplicationInsights = null;
}
WriteObject("Telemetry disabled");
}
else
{
var enabled = false;
if (System.IO.File.Exists(telemetryFile))
{
enabled = System.IO.File.ReadAllText(telemetryFile).ToLower() == "allow";
}
WriteObject($"Telemetry setting unchanged: currently {(enabled ? "enabled" : "disabled")}");
}
}
}
}
36 changes: 36 additions & 0 deletions src/Commands/Base/EnablePowerShellTelemetry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using System.Text;

namespace PnP.PowerShell.Commands.Base
{
[Cmdlet(VerbsLifecycle.Enable, "PnPPowerShellTelemetry")]
public class EnablePowerShellTelemetry : PnPSharePointCmdlet
{
[Parameter(Mandatory = false)]
public SwitchParameter Force;

protected override void ProcessRecord()
{
var userFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var telemetryFile = System.IO.Path.Combine(userFolder, ".pnppowershelltelemetry");
if (Force || ShouldContinue("Do you want to enable telemetry for PnP PowerShell?", Properties.Resources.Confirm))
{
System.IO.File.WriteAllText(telemetryFile, "allow");
Environment.SetEnvironmentVariable("PNPPOWERSHELL_DISABLETELEMETRY", "false");
Connection?.InitializeTelemetry(Connection.Context, Connection.InitializationType);
WriteObject("Telemetry enabled");
}
else
{
var enabled = false;
if (System.IO.File.Exists(telemetryFile))
{
enabled = System.IO.File.ReadAllText(telemetryFile).ToLower() == "allow" || Environment.GetEnvironmentVariable("PNPPOWERSHELL_DISABLETELEMETRY").Equals("false", StringComparison.InvariantCultureIgnoreCase);
}
WriteObject($"Telemetry setting unchanged: currently {(enabled ? "enabled" : "disabled")}");
}
}
}
}
2 changes: 0 additions & 2 deletions src/Commands/Base/PnPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,6 @@ internal void InitializeTelemetry(ClientContext context, InitializationType init
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var telemetryFile = System.IO.Path.Combine(userProfile, ".pnppowershelltelemetry");



var enableTelemetry = true;
if (Environment.GetEnvironmentVariable("PNP_DISABLETELEMETRY") != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/Base/RemoveStoredCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void ProcessRecord()
var cred = Utilities.CredentialManager.GetCredential(Name);
if (cred != null)
{
if (Force || ShouldContinue($"Remove credential {Name}?", "Confirm"))
if (Force || ShouldContinue($"Remove credential {Name}?", Properties.Resources.Confirm))
{
if (!Utilities.CredentialManager.RemoveCredential(Name))
{
Expand Down
Loading