簡體   English   中英

PowerShell CSV輸出與列

[英]PowerShell csv output with columns

我只需要有一個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
}

這與您的最后一個問題幾乎是我的答案,除了函數的更新代碼。 如果您的功能正常,也可以。 如果該功能無法正常工作,您可能需要重新表達您的問題以獲得幫助。

$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