我正在嘗試創建一個腳本,該腳本搜索計算機/服務器串列并確定是否存在名為“TestDisabledUsers”的 AD 組的每個成員的用戶組態檔。然后將結果通過管道傳輸到具有以下格式的 CSV 檔案。
ComputerName WMI_Connection Pingable Profile_Search
Computer1 Server IS Contactable TRUE User1 Exists ; User2 Exists ; User3 No Profile
Computer2 Server IS Contactable TRUE User1 No Profile ; User2 Exists ; User3 Exists
Computer3 Server IS Contactable TRUE User1 Exists ; User2 Exists ; User3 No Profile
當前腳本目前無法運行,因為它僅在Profile_Search輸出中顯示 1 個用戶 :-(
抱歉,如果這是一個簡單的解決方案,我不是最好的編碼器;-) 非常感謝任何幫助。
到目前為止,我有以下 powershell 腳本:-
Clear-History
$ErrorActionPreference= 'silentlycontinue'
$outputFolderName = 'ProfileAudit ' $(Get-Date -f dd-MM-yyyy)
$outputpath = "C:\temp\$outputFolderName"
If(!(test-path $outputpath))
{
New-Item -ItemType Directory -Force -Path $outputpath | out-null
}
$computers = Get-Content -path C:\Temp\svrs.txt
$report = @()
foreach ($computer in $computers) {
$Ping = Test-Connection -ComputerName $computer -Quiet -count 2
$wmi = gwmi win32_bios -ComputerName $computer
if ($wmi)
{
$WMIResult = 'Server IS Contactable'
$profiles = Get-ADGroupMember -Identity TestDisabledUsers | Foreach {$_.SamAccountName}
foreach ($profile in $profiles) {
$user = Get-CimInstance -ComputerName $computer -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -eq $profile }
if ($user)
{
$profileexists = ("$profile Exists") -join ' ; '
#$user | Remove-CimInstance
}
else {
$profileexists = ("$profile No Profile") -join ' ; '
}
}
$tempreport = New-Object -TypeName PSObject
$tempreport | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$tempreport | Add-Member -MemberType NoteProperty -Name WMI_Connection -Value $WMIResult
$tempreport | Add-Member -MemberType NoteProperty -Name Pingable -Value $Ping
$tempreport | Add-Member -MemberType NoteProperty -Name Profile_Search -Value $profileexists
$report = $tempreport
}
else
{
$WMIResult = 'Server NOT Contactable'
$tempreport = New-Object PSObject
$tempreport | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.ToUpper()
$tempreport | Add-Member -MemberType NoteProperty -Name WMI_Connection -Value $WMIResult
$tempreport | Add-Member -MemberType NoteProperty -Name Pingable -Value $Ping
$tempreport | Add-Member -MemberType NoteProperty -Name Profile_Search -Value $null
$report = $tempreport
}
}
$CSVFileName = 'ProfileAudit ' $(Get-Date -f dd-MM-yyyy) '.csv'
$report | Export-Csv $outputpath\$CSVFileName -NoTypeInformation
uj5u.com熱心網友回復:
試試下面的。主要問題是您正在覆寫 $profileexists 而不是在組態檔回圈中附加到它。
Clear-History
$outputpath = "C:\temp\ProfileAudit $(Get-Date -f dd-MM-yyyy)"
If(!(test-path $outputpath))
{
New-Item -ItemType Directory -Force -Path $outputpath | out-null
}
$report = Get-Content -path C:\Temp\svrs.txt | % {
$ping = Test-Connection -ComputerName $_ -Quiet -count 2
$profileexists = $null
if(gwmi win32_bios -ComputerName $_)
{
$WMIResult = 'Server IS Contactable'
$profiles = Get-ADGroupMember -Identity TestDisabledUsers | select -ExpandProperty SamAccountName
foreach ($profile in $profiles) {
$user = Get-CimInstance -ComputerName $_ -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -eq $profile }
if ($user)
{
$profileexists = "$profile Exists;"
}
else {
$profileexists = "$profile No Profile;"
}
}
}
else
{
$WMIResult = 'Server NOT Contactable'
}
[pscustomobject]@{
ComputerName = $_.ToUpper()
WMI_Connection = $WMIResult
Pingable = $Ping
Profile_Search = $profileexists
}
}
$CSVFileName = 'ProfileAudit ' $(Get-Date -f dd-MM-yyyy) '.csv'
$report | Export-Csv $outputpath\$CSVFileName -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490715.html
標籤:电源外壳
