我有一个脚本来检查给定软件的卸载状态:
$pathtofile = Get-Content ComputersToCheckRegistryAndInstallationPath.txt
$registrykey = "Snagit 10.0.2 [LC 01.01 AP] EN"
$installationpath = "Program Files (x86)\TechSmith"
foreach ($name in $pathtofile) {
if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue) {
$name
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $name)
$regkey = $reg.OpenSubKey("SOFTWARE\\Wow6432Node\\Total\\Software\\$registrykey")
if ($regkey) {
Write-Output "$registrykey Values are: " $regkey.GetValueNames()
} else {
"No $registrykey Values found"
}
if ($regkey) {
Write-Output "InstallStatus Value (void if none): " $regkey.GetValue('InstallStatus')
} else {
"No InstallStatus value found"
}
if ($regkey) {
Write-Output "UninstallStatus Value (void if none): " $regkey.GetValue('UninstallStatus')
} else {
"No UninstallStatus value found"
}
$path = Test-Path -Path "\\$name\C$\$installationpath"
if ($path -eq $true) {
Write-Output $name "$installationpath exists"
} else {
Write-Output "$installationpath does not exist"
}
} else {
Write-Output $name
}效果很好。
我唯一的问题是,对于每个软件,我们都有不同的包,我想使用通配符,例如(对于下面的示例):
$registrykey = "Snagit *"而不是:
$registrykey = "Snagit 10.0.2 [LC 01.01 AP] EN"我不能使用Get和Invoke-Command方法,因为远程计算机上没有激活PSRemoting。
从我所收集到的资料来看,没有办法解决这个问题,但也许有人在这段时间里找到了解决办法。
发布于 2018-06-21 10:00:23
枚举Software键的子键名称,并筛选该列表,以查找与您的模式匹配的名称。
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $name)
$basekey = $reg.OpenSubKey("SOFTWARE\\Wow6432Node\\Total\\Software")
$subkey = $basekey.GetSubkeyNames() | Where-Object { $_ -like $registrykey }
$regkey = $baskey.OpenSubKey($subkey)https://stackoverflow.com/questions/50965066
复制相似问题