在Powershell的帮助下,我需要找到注册表项,其中值为'Cisco',并从Value name'Uninstallstring'中获取此关键数据。 我知道这听起来有点奇怪,但是这个应用程序在每台计算机上都有不同的卸载字符串。Pwershell.registry搜索项目值其中diplayname like“”
所以
ForEach-Object -InputObject (Get-ChildItem 'HKLM:\software\microsoft\windows\currentversion\uninstall') {
$single_item = $_ | Get-Item
$single_item_properties = $single_item | Get-ItemProperty | Select-Object -Property DisplayName,UninstallString | Where-Object {($_.DisplayName -like '*Cisco*TSP*')}
$uninstall_str = ($single_item_properties | Select UninstallString)
$str_to_execute=$uninstall_str.UninstallString -replace '" .*','"'
$str_to_execute
Start-Process -FilePath $str_to_execute -ArgumentList '-s','-f1"\\sandbox\Common.Installs\Utils\un.iss"' -Wait -PassThru
}
这个脚本给我们的错误
UninstallString
"C:\Program Files (x86)\InstallShield Installation Information{01A05F96-E34D-4308-965C-65DCA4AF114D}\setup.exe"
Start-Process : This command cannot be executed due to the error: The system cannot find the file specified.
的问题是,其结果是不字符串类型。
我无法将其转换为字符串。
顺便说一句,在编辑我的问题注意到目前还不清楚你是否真的需要一个循环。是否有可能多个密钥可能匹配'* Cisco * TSP *',并且您希望为所有这些密钥执行卸载命令,或者每台计算机上只有一个密钥?在后一种情况下,我不认为需要使用** ForEach-Object **或** foreach **,因为您只是从注册表中检索单个字符串值的数据。 – 2014-11-09 06:28:20
在我想运行此脚本的每台计算机上,只安装一个思科产品,因此搜索查询应该可以工作 – mnovak 2014-11-10 07:18:25
再次考虑,您仍然需要迭代,因为您不知道密钥的名称并需要与**在哪里**过滤器。但是,请参阅我的更新答案。 – 2014-11-13 17:28:52