File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
packages/scaffold/scripts Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -123,17 +123,17 @@ function Disable-Service(
123
123
[String ]$ComputerName = " $ ( hostname) "
124
124
) {
125
125
# See https://social.technet.microsoft.com/Forums/lync/en-US/abde2699-0d5a-49ad-bfda-e87d903dd865/disable-windows-update-via-powershell?forum=winserverpowershell
126
- $service = Get-WmiObject Win32_Service - Filter " Name='$ServiceName '" - ComputerName $ComputerName - Ea 0 ;
126
+ $service = Get-CimInstance win32_service - Filter " Name='$ServiceName '" - Ea 0 ;
127
127
if ($service ) {
128
128
if ($service.StartMode -ne " Disabled" ) {
129
- $result = $service.ChangeStartMode ( " Disabled" ).ReturnValue;
129
+ $result = ( Invoke-CimMethod - InputObject $service - methodname ChangeStartmode - Arguments @ { startmode = ' Disabled' } ).ReturnValue;
130
130
if ($result ) {
131
131
Write-Host " Failed to disable the '$ServiceName ' service on $ComputerName . The return value was $result ." - ForegroundColor Red;
132
132
} else {
133
133
Write-Host " Successfully disabled the '$ServiceName ' service on $ComputerName ." - ForegroundColor Green;
134
134
}
135
135
if ($service.State -eq " Running" ) {
136
- $result = $service. StopService () .ReturnValue;
136
+ $result = ( Invoke-CimMethod - InputObject $service - methodname StopService).ReturnValue .ReturnValue;
137
137
if ($result ) {
138
138
Write-Host " Failed to stop the '$ServiceName ' service on $ComputerName . The return value was $result ." - ForegroundColor Red;
139
139
} else {
Original file line number Diff line number Diff line change 6
6
}
7
7
8
8
Write-Output " Disabling Windows Update Medic Service"
9
+ # Windows Update Medic Service can only be disabled via the registry
9
10
Set-ItemProperty - Path ' HKLM:\SYSTEM\CurrentControlSet\Services\WaaSMedicSvc' - Name ' Start' - value 4
10
- Disable-Service (" WaaSMedicSVC" );
11
+ Write-Host " Successfully disabled the 'WaaSMedicSVC' service on $ComputerName ." - ForegroundColor Green;
12
+ $WaaSMedicSVC = get-ciminstance win32_service - Filter " Name='WaaSMedicSVC'" - Ea 0 ;
13
+ if ($WaaSMedicSVC.State -eq " Running" ){
14
+ $ComputerName = " $ ( hostname) "
15
+ $result = (Invoke-CimMethod - InputObject $WaaSMedicSVC - methodname StopService).ReturnValue
16
+ if ($result ) {
17
+ Write-Host " Failed to stop the 'WaaSMedicSVC' service on $ComputerName . The return value was $result ." - ForegroundColor Red;
18
+ } else {
19
+ Write-Host " Successfully stopped the 'WaaSMedicSVC' service on $ComputerName ." - ForegroundColor Green;
20
+ }
21
+ }
11
22
12
23
Write-Output " Disabling Update Orchestrator Service"
13
24
Disable-Service (" UsoSvc" );
Original file line number Diff line number Diff line change @@ -6,5 +6,3 @@ force-mkdir "HKLM:\SOFTWARE\Policies\Microsoft\Windows"
6
6
7
7
Set-ItemProperty - Path " HKLM:\SOFTWARE\Policies\Microsoft\Windows" - Name " EnableScripts" - Type DWord - Value 1
8
8
Set-ItemProperty - Path " HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" - Name " ExecutionPolicy" - Type String - Value " RemoteSigned"
9
-
10
- HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows
You can’t perform that action at this time.
0 commit comments