我只需要输出一个csv作为输出,其中一列中的服务器名称和第二列中的结果。我无法使用export-csv cmdlet,因为即时通讯使用旧版本的PS。非常感谢你的帮助!
$servers= Get-Content -path .\Server_List.txt
Function get-UserAccountControl ($server)
{
[string]$RegPath = "Software\Microsoft\Windows\CurrentVersion\Policies\System"
[string]$RegValue = "EnableLUA"
$OpenRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$server)
$subKey = $OpenRegistry.OpenSubKey($RegPath,$false)
$UAC = ($Subkey.GetValue($RegValue) -eq 1)
if ($uac -eq 1 )
{
return( " uac is enabled")
}
else
{
return (" uac is disabled")
}
}
foreach ($srv in $servers)
{
write-host "The server $srv"
$useraccount= get-UserAccountControl($srv)
write-output $useraccount
}
答案 0 :(得分:0)
除了您更新的函数代码之外,这与your last question完全相同。如果你的功能有效,那也是如此。如果该功能不起作用,您可能需要重新定义您的问题以获得帮助。
$servers= Get-Content -path .\Server_List.txt
Function get-UserAccountControl ($server)
{
[string]$RegPath = "Software\Microsoft\Windows\CurrentVersion\Policies\System"
[string]$RegValue = "EnableLUA"
$OpenRegistry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$server)
$subKey = $OpenRegistry.OpenSubKey($RegPath,$false)
$UAC = ($Subkey.GetValue($RegValue) -eq 1)
if ($uac -eq 1 )
{
return( " uac is enabled")
}
else
{
return (" uac is disabled")
}
}
"Server,Results"|Out-File UAC_audit_results.csv
foreach ($srv in $servers)
{
write-host "The server $srv"
$useraccount= get-UserAccountControl($srv)
"{0},{1}" -f $srv, $useraccount
write-output $useraccount
}