-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSet-DisableClipSVCSubscription.ps1
More file actions
92 lines (78 loc) · 2.83 KB
/
Copy pathSet-DisableClipSVCSubscription.ps1
File metadata and controls
92 lines (78 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<#
.SYNOPSIS
Disable the ClipSVC subscription functionality.
.DESCRIPTION
This script configures DisableSubscription as a DWORD with the value 1 under
the ClipSVC Parameters registry key.
.NOTES
Version: 1.0
Author: Martin Himken
Initial creation date: 27.08.26
Last change: 27.08.26
Changes: see changelog.md
Intune Platform Script settings:
* Run this script using the logged-on credentials: No
* Enforce script signature check: No
* Run script in 64-bit PowerShell: Yes
#>
$ErrorActionPreference = 'Stop'
function Get-RegistryValueKind {
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$Name
)
try {
$item = Get-Item -LiteralPath $Path -ErrorAction Stop
return $item.GetValueKind($Name)
} catch {
return $null
}
}
function Set-RegistryDwordValue {
param(
[Parameter(Mandatory = $true)]
[string]$Path,
[Parameter(Mandatory = $true)]
[string]$Name,
[Parameter(Mandatory = $true)]
[int]$Value
)
$valueKind = Get-RegistryValueKind -Path $Path -Name $Name
if ($null -eq $valueKind) {
New-ItemProperty -LiteralPath $Path -Name $Name -Value $Value -PropertyType DWord -Force | Out-Null
return 'Created'
}
if ([string]$valueKind -ne 'DWord') {
Remove-ItemProperty -LiteralPath $Path -Name $Name -Force -ErrorAction Stop
New-ItemProperty -LiteralPath $Path -Name $Name -Value $Value -PropertyType DWord -Force | Out-Null
return 'RecreatedAsDword'
}
$currentValue = Get-ItemPropertyValue -LiteralPath $Path -Name $Name -ErrorAction Stop
if ([int]$currentValue -ne $Value) {
Set-ItemProperty -LiteralPath $Path -Name $Name -Value $Value -Type DWord -Force | Out-Null
return 'Updated'
}
return 'AlreadyCompliant'
}
$registryPath = 'HKLM:\SYSTEM\CurrentControlSet\Services\ClipSVC\Parameters'
$valueName = 'DisableSubscription'
$desiredValue = 1
try {
if (-not (Test-Path -LiteralPath $registryPath)) {
New-Item -Path $registryPath -Force | Out-Null
Write-Output "Created registry path $registryPath."
}
$result = Set-RegistryDwordValue -Path $registryPath -Name $valueName -Value $desiredValue
$verifyKind = Get-RegistryValueKind -Path $registryPath -Name $valueName
$verifyValue = Get-ItemPropertyValue -LiteralPath $registryPath -Name $valueName -ErrorAction Stop
if ([string]$verifyKind -ne 'DWord' -or [int]$verifyValue -ne $desiredValue) {
throw "Verification failed. '$valueName' is type $verifyKind with value $verifyValue; expected DWORD $desiredValue."
}
Write-Output "SUCCESS: '$valueName' at $registryPath is DWORD $desiredValue ($result)."
exit 0
} catch {
Write-Output "ERROR: Configuration failed. $($_.Exception.Message)"
exit 1
}