@@ -22,13 +22,21 @@ Restart-App Outlook 'C:\Program Files\Microsoft Office\root\Office16\OUTLOOK.EXE
22
22
. PARAMETER GetCommand
23
23
If specified then report the command line of the specified running process. This value can be
24
24
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
25
33
#>
26
34
27
35
# CmdletBinding adds -Verbose functionality, SupportsShouldProcess adds -WhatIf
28
- [CmdletBinding (SupportsShouldProcess = $true )]
36
+ [CmdletBinding (SupportsShouldProcess = $true )]
29
37
30
38
param (
31
- [Parameter (Mandatory = $true )] [string ] $Name ,
39
+ [Parameter (Mandatory = $true )] [string ] $Name ,
32
40
[string ] $Command ,
33
41
[string ] $Arguments ,
34
42
[switch ] $Register ,
48
56
else
49
57
{
50
58
# 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
52
60
Write-Host " ... found process $Name , ID $ ( $process.ID ) , running $cmd "
53
61
}
54
62
}
60
68
if ($process -ne $null )
61
69
{
62
70
# 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(' "' , ' ' )
64
72
Write-Host " ... found process $Name running $cmd "
65
73
66
74
# terminating instead of graceful shutdown because can't connect using this:
@@ -100,19 +108,19 @@ Begin
100
108
$cmd = " Restart-App -Name '$Name ' -Command '$Command ' -Arguments '$Arguments '"
101
109
102
110
$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 "" "
104
112
105
113
$task = Get-ScheduledTask - TaskName " Restart $Name " - ErrorAction:SilentlyContinue
106
- if ($task -eq $null )
107
- {
114
+ if ($task -eq $null )
115
+ {
108
116
Write-Host " ... creating scheduled task 'Restart $Name '"
109
117
110
118
Register-ScheduledTask `
111
119
- Action $action `
112
120
- Trigger $trigger `
113
121
- TaskName " Restart $Name " `
114
122
- RunLevel Highest | Out-Null
115
- }
123
+ }
116
124
else
117
125
{
118
126
Write-Host " ... scheduled task 'Restart $Name ' is already registered"
0 commit comments