Skip to content

Commit b3f99f2

Browse files
committed
patch restart-app gwmi to gcim
1 parent 346a72c commit b3f99f2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

Modules/Scripts/Enable-MultiRdp.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Begin
8989

9090
# termservice is harder to stop...
9191
sc.exe config TermService start= disabled
92-
$svcid = gwmi -Class Win32_Service -Filter "Name LIKE 'TermService'" | Select -ExpandProperty ProcessId
92+
$svcid = Get-CimInstance -Class Win32_Service -Filter "Name LIKE 'TermService'" | Select -ExpandProperty ProcessId
9393
taskkill /f /pid $svcid
9494
}
9595

Modules/Scripts/Restart-App.ps1

+16-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,21 @@ Restart-App Outlook 'C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE
2222
.PARAMETER GetCommand
2323
If specified then report the command line of the specified running process. This value can be
2424
used to specify the Command parameter when registering.
25+
26+
.DESCRIPTION
27+
Example:
28+
29+
❯ restart-app -get outlook
30+
... found process outlook, ID 3972, running "C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE"
31+
32+
> restart-app -command outlook -register
2533
#>
2634

2735
# CmdletBinding adds -Verbose functionality, SupportsShouldProcess adds -WhatIf
28-
[CmdletBinding(SupportsShouldProcess=$true)]
36+
[CmdletBinding(SupportsShouldProcess = $true)]
2937

3038
param (
31-
[Parameter(Mandatory = $true)] [string] $Name,
39+
[Parameter(Mandatory = $true)] [string] $Name,
3240
[string] $Command,
3341
[string] $Arguments,
3442
[switch] $Register,
@@ -48,7 +56,7 @@ Begin
4856
else
4957
{
5058
# get the commandline from the process, strip off quotes
51-
$cmd = (gwmi win32_process -filter ("ProcessID={0}" -f $process.id)).CommandLine
59+
$cmd = (Get-CimInstance win32_process -filter ("ProcessID={0}" -f $process.id)).CommandLine
5260
Write-Host "... found process $Name, ID $($process.ID), running $cmd"
5361
}
5462
}
@@ -60,7 +68,7 @@ Begin
6068
if ($process -ne $null)
6169
{
6270
# get the commandline from the process, strip off quotes
63-
$script:cmd = (gwmi win32_process -filter ("ProcessID={0}" -f $process.id)).CommandLine.Replace('"', '')
71+
$script:cmd = (Get-CimInstance win32_process -filter ("ProcessID={0}" -f $process.id)).CommandLine.Replace('"', '')
6472
Write-Host "... found process $Name running $cmd"
6573

6674
# terminating instead of graceful shutdown because can't connect using this:
@@ -100,19 +108,19 @@ Begin
100108
$cmd = "Restart-App -Name '$Name' -Command '$Command' -Arguments '$Arguments'"
101109

102110
$trigger = New-ScheduledTaskTrigger -Daily -At 2am;
103-
$action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-Command ""$cmd"""
111+
$action = New-ScheduledTaskAction -Execute 'pwsh' -Argument "-Command ""$cmd"""
104112

105113
$task = Get-ScheduledTask -TaskName "Restart $Name" -ErrorAction:SilentlyContinue
106-
if ($task -eq $null)
107-
{
114+
if ($task -eq $null)
115+
{
108116
Write-Host "... creating scheduled task 'Restart $Name'"
109117

110118
Register-ScheduledTask `
111119
-Action $action `
112120
-Trigger $trigger `
113121
-TaskName "Restart $Name" `
114122
-RunLevel Highest | Out-Null
115-
}
123+
}
116124
else
117125
{
118126
Write-Host "... scheduled task 'Restart $Name' is already registered"

0 commit comments

Comments
 (0)