0

i just need to have an csv as output with the name of the servers in one column and the result in the second column. I cannot use the export-csv cmdlet because im using a old version of PS. Thank you very much for your help!

$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
}
2
  • Ok, so this is almost the exact same as the last question where I helped you get the desired format, except here you actually have a functional remote reg query (I think so at least from first glance). Why not apply my formatting answer from the last one to the functional code you have here? Commented Jul 23, 2014 at 23:26
  • Export-Csv exists since PowerShell 1.0 Have a look here. Commented Jul 24, 2014 at 5:07

1 Answer 1

0

This is pretty much my same answer as your last question, except with your updated code for the function. If your function works, this will too. If the function doesn't work, you may want to re-phrase your question to get help with that.

$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
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.