下面是我的powershell脚本片段,用于获取所有已安装的应用程序:
$tPatchObject = @() #initialize array
#invoking the native powershell(32 bit/64 bit)
$tPatchObject = &"$env:systemroot\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -Command {Get-Childitem "HKLM://SOFTWARE//Microsoft//Windows//CurrentVersion//Uninstall//*" | Get-ItemProperty | Sort-Object DisplayName -Unique;};
#appending applications from a different path to same array
$tPatchObject += &"$env:systemroot\sysnative\windowspowershell\v1.0\powershell.exe" -NonInteractive -NoProfile -Command {Get-Childitem "HKLM://SOFTWARE//Wow6432Node//Microsoft//Windows//CurrentVersion//Uninstall//*" | Get-ItemProperty | Sort-Object DisplayName -Unique}在Windows 2008 R2系统上进行测试时,如果直接从powershell执行,它就会给出适当的输出。但是,在Golang中编译的可执行文件的一部分执行相同的脚本会产生错误。
方法调用失败,因为System.Management.Automation.PSObject不包含名为“op_a”的方法。
仅在Windows服务器2008系统上才会面临此问题。我的假设是由于调用&"powershell.exe"而出现的问题
发布于 2020-06-01 08:18:30
试试这个,LookPath
cmd := `Get-Childitem "HKLM://SOFTWARE//Microsoft//...`
ps, _ := exec.LookPath("powershell.exe")
args := append([]string{"-NoProfile", "-NonInteractive", cmd})
out, _ := exec.Command(ps, args...).Output()https://stackoverflow.com/questions/62116849
复制相似问题