Csv 需要powershell帮助导出4节数据
下面的列表将一份名单与我们在我的职位上的广告进行了比较。然而,每一部分都列出了很多名字,使我无法向上滚动。我尝试过使用。\ylaudit2.ps1 | out文件workdayaudit1.csv,但它只给了我一个空白的csv文件。有人能帮我吗Csv 需要powershell帮助导出4节数据,csv,powershell,Csv,Powershell,下面的列表将一份名单与我们在我的职位上的广告进行了比较。然而,每一部分都列出了很多名字,使我无法向上滚动。我尝试过使用。\ylaudit2.ps1 | out文件workdayaudit1.csv,但它只给了我一个空白的csv文件。有人能帮我吗 $script:YLUserCSV = Import-CSV "c:\ylusers.csv" $result = Test-Path "c:\\ylusers.csv" if($result -eq $FALSE){ Write-Hos
$script:YLUserCSV = Import-CSV "c:\ylusers.csv"
$result = Test-Path "c:\\ylusers.csv"
if($result -eq $FALSE){
Write-Host "Path to CSV does not exist: \\$env:computername\c$\ylusers.csv"
break
}
}
Function Analyze-UserAuthentication{
foreach ($row in $script:YLUserCSV){
write-host "$row.username"
if ($row.authenticationtype -eq "LDAP"){
$script:LDAPUsers += $row.username
}
elseif ($row.authenticationtype -eq "DATABASE"){
$script:DBUsers += $row.username
}
}
}
Function Check-DBUsers {
Write-Host "`nChecking accounts that use database authentication..." - ForegroundColor Yellow
$DBUsersInAD = @("`n")
foreach ($user in $script:DBUsers){
$DBUserCheck = Get-QADUser $user
if ($DBUserCheck -eq $NULL){
Write-Host "No Active Directory user $user found."
}
elseif ($DBUserCheck -ne $NULL){
$DBUsersInAD += $DBUserCheck.Name+"`n"
}
else {
out-null
}
}
Write-Host "`nDatabase authenticated Yodle Live users associated with AD accounts:" -ForegroundColor Yellow
Write-Host $DBUsersInAD | FL
}
Function Check-LDAPUsers {
Write-Host "`nChecking accounts that use LDAP authentication...-ForegroundColor Yellow
$LDAPUsersinAD = @("`n")
$inADandEnabled = @("`n")
$inADandDisabled = @("`n")
$notinAD = @("`n")
foreach ($user in $script:LDAPUsers){
$LDAPUserCheck = Get-QADUser $user
if ($LDAPUserCheck -ne $NULL){
$LDAPUsersinAD += $LDAPUserCheck.Name+"`n"
if ($LDAPUserCheck.AccountIsDisabled -ne $TRUE){
$inADandEnabled += $LDAPUserCheck.Name+"`n"
}
elseif ($LDAPUserCheck.AccountIsDisabled -eq $TRUE){
$inADandDisabled += $LDAPUserCheck.Name+"`n"
}
}
else {
$notinAD += $user+"`n"
$LDAPUserCheck = $NULL
}
}
Write-Host "`nEnabled Yodle Live accounts associated with disabled AD Users:" -ForegroundColor Yellow
Write-Host $inADandDisabled | FL
Write-Host "`nEnabled Yodle Live accounts not associated with any AD User:" -ForegroundColor Yellow
Write-Host $notinAD | FL
}
Set-ScriptVars
Import-UserData
Analyze-UserAuthentication
Check-DBUsers
Check-LDAPUsers
无法保存输出的原因是您正在使用
Write Host
<代码>写入主机仅向交互控制台写入文本,例如状态消息等
如果您需要能够将输出保存到文件中,则需要删除输出要保存的数据的行上的Write Host
(或使用Write output
),这样对象将沿着管道传递,以便|Out file
可以捕获并保存它们
例:替换:
Write-Host "`nDatabase authenticated Yodle Live users associated with AD accounts:" -ForegroundColor Yellow
Write-Host $DBUsersInAD | FL
#lots of code....
#...
Write-Host "`nEnabled Yodle Live accounts associated with disabled AD Users:" -ForegroundColor Yellow
Write-Host $inADandDisabled | FL
Write-Host "`nEnabled Yodle Live accounts not associated with any AD User:" -ForegroundColor Yellow
Write-Host $notinAD | FL
与:
"Database authenticated Yodle Live users associated with AD accounts:"
$DBUsersInAD
#lots of code....
#...
"Enabled Yodle Live accounts associated with disabled AD Users:"
$inADandDisabled
"Enabled Yodle Live accounts not associated with any AD User:"
$notinAD