我正在编写一个脚本,该脚本将删除存储在注册表中的App-V密钥。用户打开应用程序时,会在以下位置创建密钥:
HKLM\SOFTWARE\Microsoft\AppV\MAV\Configuration\Packages\**PackageID**\UserConfigEx\**SID**
这个
PackageID
还有
SID
每次都是唯一的,我希望能够删除
希德
每个
包装
钥匙
用户将输入SID,然后我希望使用通配符(如果可能)导航到存在的每个包ID。
到目前为止,我有以下几点:
#Take user input
$SID = Read-Host "Please enter users SID"
$computer = Read-Host "Please enter computer name"
#Test connection
Write-Host "Connecting to $computer"
if (Test-Connection -ComputerName $computer -Quiet -BufferSize 16 -Count 1) {
#Connect to registry and delete key
try
{
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(âLocalMachineâ, $computer)
$regKey = $reg.OpenSubKey(âHKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\AppV\\MAV\\Configuration\\Packages\\*\\UserConfigEx\\$SIDâ,$true )
if ($regkey.GetValue(â$SIDâ))
{
$regKey.DeleteValue(â$SIDâ)
Write-Host
Write-Host "$SID key deleted successfully" -ForegroundColor Green
}
else
{
Write-Host
Write-Host "No keys with this SID exist." -ForegroundColor Red
}
} catch {
$ErrorMessage = $_.Exception.Message
Write-Host "Unable to connect to $computer. Error: $($ErrorMessage)." -ForegroundColor Red
}
} else
{
Write-Host "Unable to connect to $computer. Please ensure correct computer name / IP address has been entered correctly." -ForegroundColor Red
}
如果我运行此功能,我会收到:
You cannot call a method on a null-valued expression.
At line:51 char:9
+ if ($regkey.GetValue(â$SIDâ))
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
我正在使用一些我得到帮助的脚本
here
远程连接到机器。