如何在64位计算机上的Windows PowerShell上运行脚本块

时间:2019-03-22 09:10:57

标签: windows powershell 64-bit

我想运行脚本块来查找系统上可用的软件。 下面是我的代码段。

$scriptBlock = {
    $key = Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' |
           Where-Object { $_.DisplayName -match 'Skype' };
    return $key
}

$installed64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -NoProfile -NonInteractive -Command $scriptBlock)

当我在64位计算机上执行上述命令时,出现错误消息

& : The term 'C:\WINDOWS\sysnative\WindowsPowerShell\v1.0\powershell.exe' is
not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify
that the path is correct and try again.
At line:1 char:20
+ ... led64 = @(& "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powersh ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\WINDOWS\sysn...\powershell.exe:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我想在“ NT AUTHORITY \ SYSTEM” PowerShell中运行命令。

如何运行脚本块?

0 个答案:

没有答案