简体   繁体   中英

PowerShell csv output with columns

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
}

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM