我正在尝试创建注册表项一段时间。
环境:
应在多台计算机上创建以下条目:
[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system] "LocalAccountTokenFilterPolicy"=dword:00000001
为此,我想使用以下脚本
$Computers = Get-Content "C:\Scripts\Clients.txt"
$Path = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"
$Name = "LocalAccountTokenFilterPolicy"
$PropertyType = "DWord"
$Value = 1
$results = foreach ($computer in $Computers) {
if (Test-Connection -ComputerName $computer -Count 1 -Quiet) {
try {
Set-ItemProperty -Path $path -Name $Name -Value $Value -Type $PropertyType -ErrorAction 'Stop'
$status = "Success"
} catch {
$status = "Failed"
}
} else {
$status = "Unreachable"
}
New-Object -TypeName PSObject -Property @{
'Computer' = $computer
'Status' = $status
}
}
$results | Export-Csv -NoTypeInformation -Path "./error.csv"
脚本已执行,没有错误出现,但未创建条目。 我的错误在哪里?