0
いくつかのキーワードを検索し、サブキーが見つかった「ツリー」を削除したいパスの配列に基づいて、いくつかのキーをレジスタから削除しようとしています。検索と削除の試行でエラーが発生する
しかし、それを理解しようとした後、ダウン以下のスクリプトは、常にこのエラーが返されます。
It's not possible to call a method in an expression witha null value.
At line:17 character:1
+ $SubKeys=$RegisterKey.GetSubKeyNames()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Begin
{
$computername = $env:computername
"Script Started $(Get-Date)"
[array]$KeysToRemove="HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall","HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\Installer\\Products","HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\OnlineManagement","HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products","HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Components","HKEY_CLASSES_ROOT\\Installer\\Products"
}
Process
{
foreach($keys in $KeysToRemove)
{
if($KeysToRemove -eq "HKEY_CLASSES_ROOT\\Installer\\Products")
{$Register = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('ClassesRoot', $computername)}
else {$Register = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computername)}
$RegisterKey = $Register.OpenSubKey($keys)
$SubKeys=$RegisterKey.GetSubKeyNames()
foreach($key in $SubKeys){
if($key.Contains('Microsoft\.Intune'))
{
"Key found: $key"
"Deleting it from register."
$Register.DeleteSubKeyTree($key)
}
else {"No key was found."}
}
}
"Script Ended $(Get-Date)"
}
この関数はSubKeyNamesを返します。どのようにしてこのサブキーのすべての値を検索できますか? – pulgalipe
$ Value = $ UninstallKey.GetValue($ _) 実行するたびに、パラメータとして渡すべきいくつかの値を尋ねます。 次のパラメータの値を提供するパイプラインのコマンド1の位置1に レットますforeach-オブジェクト: ダウン以下メッセージ従っ プロセスを[0]: それをデバッグしようとしなし値は$上catchedされています値変数。 – pulgalipe