简体   繁体   English

PowerShell CSV输出与列

[英]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. 我只需要有一个csv作为输出,第一列中的服务器名称,第二列中的结果。 I cannot use the export-csv cmdlet because im using a old version of PS. 我无法使用export-csv cmdlet,因为即时通讯使用的是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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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