powershell - 无法在powershell中执行字符串
问题描述
somescript.ps1 将返回一个字符串,它是一个命令
$PATHS = @("HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall") $SOFTWARE = "Microsoft Azure Information Protection" ForEach ($path in $PATHS) { $installed = Get-ChildItem -Path $path | ForEach { Get-ItemProperty $_.PSPath } | Where-Object { $_.DisplayName -match $SOFTWARE } | Select-Object -Property DisplayName,DisplayVersion,UninstallString ForEach ($app in $installed) { Write-Output "$($app.UninstallString)"} }
现在,我有一个命令,它是从上述查询返回的字符串,如下所示:
PS D:\FolderName> .\somescript.ps1
"C:\ProgramData\Package Cache\{21b41fEE-93c0-498f-a284-659d275b4076}\AzInfoProtection.exe" /uninstall
MsiExec.exe /I{7FA8B359-E9D7-4037-8DE3-A28F2603D743}
我需要执行上面返回的字符串,这是 PowerShell 中的一个命令
"C:\ProgramData\Package Cache{21b41fEE-93c0-498f-a284-659d275b4076}\AzInfoProtection.exe" /卸载 MsiExec.exe /I{7FA8B359-E9D7-4037-8DE3-A28F2603D743}
我收到如下错误
PS C:\ProgramData\Package Cache> C:\ProgramData\Package Cache{21b41fEE-93c0-498f-a284-659d275b4076}\AzInfoProtection.exe /uninstall MsiExec.exe /I{7FA8B359-E9D7-4037-8DE3-A28F2603D743}
C:\ProgramData\Package : The term 'C:\ProgramData\Package' 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:1
+ C:\ProgramData\Package Cache\{21b41fEE-93c0-498f-a284-659d275b4076}\A ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\ProgramData\Package:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
如何修复在 PowerShell 中执行此命令的命令?
解决方案
推荐阅读
- shell - 如何在 sh 中使用 `< <(tail ...)` 而不是 bash?
- python - 如何在 pandas DataFrame 中使用两种不同的方式来索引同一轴
- javascript - 网页的动态内容未完全使用 Htmlunit WebClient 加载
- java - 如何验证随机数生成并提供计算
- odoo - Odoo 9.0 电子邮件通知不会自动触发
- node.js - 为什么我在收到 409 响应时无法读取消息或状态码?
- c# - .NET Core DI,为包注册一个默认实现
- c# - cSharp编程,.net框架
- java - 在 try catch 块之外使用变量(Java)
- sql - ISnull 函数需要两个参数