Сводка: почему Test-Path
возвращает разные значения?
Это скрипт.Хотите проверить, существует ли путь к реестру.
$regpath = Get-Content -Path c:\temp\regpath.txt
foreach ($rp in $regpath) {
$testkey = Test-Path "$rp"
Write-Host $testkey
if (!$testkey) {
Write-Host "Does not exists == $rp"
}
}
Это два примера пути к реестру, который нужно проверить.
Пример 1:
$regpath = "HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\Triple DES 168"
Пример 2:
$regpath = Get-Content -Path c:\temp\regpath.txt
## this is sample entry of regpath.txt
"HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Ciphers\Triple DES 168"
Результаты разные.В примере 1 значение `Test-Path равно TRUE:
PS C:\temp> foreach ($rp in $regpath) {
>> $testkey = Test-Path "$rp"
>> Write-Host $testkey
>> if (!$testkey) {
>> Write-Host "Does not exists == $rp"
>> }
>> }
>>
True
В примере 2 (из файла) значение Test-Path
равно FALSE:
PS C:\temp> foreach ($rp in $regpath) {
>> $testkey = Test-Path "$rp"
>> Write-Host $testkey
>> if (!$testkey) {
>> Write-Host "Does not exists == $rp"
>> }
>> }
>>
False
Does not exists == "HKLM:SYSTEM\CurrentControlSet\Control \SecurityProviders\SCHANNEL\Ciphers\Triple DES 168"
False
Does not exists == "HKLM:SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\KeyExchangeAlgorithms\PKCS"