Powershell,Get-WindowsCapability:为什么会收到关于不支持路径格式的错误?

时间:2020-02-03 19:45:15

标签: powershell ssh path admin

我正在运行下面粘贴的脚本:

function grep { $input | out-string -stream | select-string $args }
function Install-SSH { Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Client*' |  grep('Name\s*:\s(\S+)') | % { Add-WindowsCapability -Online -Name $_.matches.groups[1].Value } }
function Uninstall-SSH { Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Client*' |  grep('Name\s*:\s(\S+)') | % { Remove-WindowsCapability -Online -Name $_.matches.groups[1].Value } }

if((([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")) {
    #Administrator Payload goes here.
    Write-Host -ForegroundColor Green "Installing SSH..."
    Get-WindowsCapability -Online
    Pause #Debugging purposes
} else {
    Write-Host -ForegroundColor Red "Powershell script running as Guest. Trying to run as administrator..."
    Set-Location -Path $PSScriptRoot
    $registryPath = "HKCU:\Environment"
    $Name = "windir"
    $Value = "powershell -ep bypass -w n $PSCommandPath;#"
    Set-ItemProperty -Path $registryPath -Name $name -Value $Value
    schtasks /run /tn \Microsoft\Windows\DiskCleanup\SilentCleanup /I | Out-Null
    Remove-ItemProperty -Path $registryPath -Name $name
}

我在输出中遇到以下错误,并且我在网上找不到任何有助于理解此处发生情况的信息。我在做什么错了?

Installing SSH...
Get-WindowsCapability : Set current directory to C:\WINDOWS\system32 failed:The given path's format is not supported.
At D:\Code\projects\powershell-scripts\SSHInstallation.ps1:10 char:5
+     Get-WindowsCapability -Online
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Microsoft.Dism.Commands.BaseDismObject:BaseDismObject) [Get-WindowsCapabi
   lity], Exception
    + FullyQualifiedErrorId : BaseCmdLet,Microsoft.Dism.Commands.GetWindowsCapabilityCommand

0 个答案:

没有答案