$file = "D:\Transcripts\ADPCverify\" + (get-date -Format yyyymmdd-hhmmss) + ".txt"
start-transcript -LiteralPath $file
$date = Get-Date
$computers = Get-Content D:\Content\ADPCverify\unverified.txt | sort-object -unique
$list = Get-Content D:\Content\ADPCDisable\computers.txt
$name = 'null'
$server = ''
ForEach($computer in $computers){
Try{
$PCObject = Get-ADComputer -Identity $computer -Server $server -Properties *
$name = $PCObject.Name
$OS = $PCObject.OperatingSystem
$pwdLastSet = [DateTime]::FromFiletime([Int64]::Parse($PCobject.pwdLastSet))
$TimeSince = New-TimeSpan $pwdLastSet $date
if($OS.StartsWith('Windows Server')){
Add-Content D:\Content\ADPCDisable\FailedComputers.txt $computer
write-host "Machine " $computer " has a server OS and will be added to the failed computer list."
}elseif($TimeSince.TotalDays -lt 10){
Add-Content D:\Content\ADPCDisable\FailedComputers.txt $computer
write-host "Machine " $computer "'s password was reset " + $TimeSince.TotalDays + " days ago and has been added to the failed computer list."
}else{
Add-Content D:\Content\ADPCDisable\Computers.txt $name
write-host "Machine " $name " has been succesfully added to the computers to disable list."
}
}
Catch{
Add-Content D:\Content\ADPCDisable\FailedComputers.txt $computer
write-host "Machine " $computer " does not exist and has been added to the failed computers list."
}
}
Stop-Transcript
Este é o resultado final. Eu usei a opção try / catch para suprimir erros. Meu problema foi com a comparação -contains. Obrigado por toda a ajuda!