Skip to content

Commit 043a20b

Browse files
authored
Update script to account for PS7.3 native command argument parsing changes (#642)
* Update script to account for PS7.3 native command argument parsing changes * Update version
1 parent 1bead19 commit 043a20b

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

contrib/win32/openssh/install-sshd.ps1

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,19 @@ if (Get-Service ssh-agent -ErrorAction SilentlyContinue)
3939
sc.exe delete ssh-agent 1>$null
4040
}
4141

42-
# unregister etw provider
43-
wevtutil um `"$etwman`"
42+
# Unregister etw provider
43+
# PowerShell 7.3+ has new/different native command argument parsing
44+
if ($PSVersiontable.PSVersion -le '7.2.9') {
45+
wevtutil um `"$etwman`"
46+
}
47+
else {
48+
wevtutil um "$etwman"
49+
}
4450

4551
# adjust provider resource path in instrumentation manifest
4652
[XML]$xml = Get-Content $etwman
47-
$xml.instrumentationManifest.instrumentation.events.provider.resourceFileName = $sshagentpath.ToString()
48-
$xml.instrumentationManifest.instrumentation.events.provider.messageFileName = $sshagentpath.ToString()
53+
$xml.instrumentationManifest.instrumentation.events.provider.resourceFileName = "$sshagentpath"
54+
$xml.instrumentationManifest.instrumentation.events.provider.messageFileName = "$sshagentpath"
4955

5056
$streamWriter = $null
5157
$xmlWriter = $null
@@ -114,16 +120,21 @@ if (Test-Path $sshProgDataPath)
114120
}
115121
}
116122

117-
#register etw provider
118-
wevtutil im `"$etwman`"
123+
# Register etw provider
124+
# PowerShell 7.3+ has new/different native command argument parsing
125+
if ($PSVersiontable.PSVersion -le '7.2.9') {
126+
wevtutil im `"$etwman`"
127+
} else {
128+
wevtutil im "$etwman"
129+
}
119130

120131
$agentDesc = "Agent to hold private keys used for public key authentication."
121-
New-Service -Name ssh-agent -DisplayName "OpenSSH Authentication Agent" -BinaryPathName `"$sshagentpath`" -Description $agentDesc -StartupType Manual | Out-Null
132+
New-Service -Name ssh-agent -DisplayName "OpenSSH Authentication Agent" -BinaryPathName "$sshagentpath" -Description $agentDesc -StartupType Manual | Out-Null
122133
sc.exe sdset ssh-agent "D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;RP;;;AU)"
123134
sc.exe privs ssh-agent SeAssignPrimaryTokenPrivilege/SeTcbPrivilege/SeBackupPrivilege/SeRestorePrivilege/SeImpersonatePrivilege
124135

125136
$sshdDesc = "SSH protocol based service to provide secure encrypted communications between two untrusted hosts over an insecure network."
126-
New-Service -Name sshd -DisplayName "OpenSSH SSH Server" -BinaryPathName `"$sshdpath`" -Description $sshdDesc -StartupType Manual | Out-Null
137+
New-Service -Name sshd -DisplayName "OpenSSH SSH Server" -BinaryPathName "$sshdpath" -Description $sshdDesc -StartupType Manual | Out-Null
127138
sc.exe privs sshd SeAssignPrimaryTokenPrivilege/SeTcbPrivilege/SeBackupPrivilege/SeRestorePrivilege/SeImpersonatePrivilege
128139

129140
Write-Host -ForegroundColor Green "sshd and ssh-agent services successfully installed"

contrib/win32/openssh/uninstall-sshd.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ else {
1717
Write-Host -ForegroundColor Yellow "sshd service is not installed"
1818
}
1919

20-
# unregister etw provider
21-
wevtutil um `"$etwman`"
20+
# Unregister etw provider
21+
# PowerShell 7.3+ has new/different native command argument parsing
22+
if ($PSVersiontable.PSVersion -le '7.2.9') {
23+
wevtutil um `"$etwman`"
24+
}
25+
else {
26+
wevtutil um "$etwman"
27+
}
2228

2329
if (Get-Service ssh-agent -ErrorAction SilentlyContinue)
2430
{

0 commit comments

Comments
 (0)