What I'm trying tp acomplish is to create 2 different list , computers on (or with a service running) and those that are off. Then from the list that is on I want to change the local admin password.
I have test the password change portion of this script and seem to work fine. I can not get the sorting to work. the If serverice is running does not work and the esle do not put the computer name in the file. If I change the $_.Name to a word , the word does go into the file.
any help or suggestions would be great.
$Computers = Read-Host "Enter Machine Name"
$NewPass = Read-Host "Enter New Password"
Get-QADComputer $Computers | ForEach-Object {add-content -path List.txt -value $_.Name}
Get-content List.txt | foreach { get-Service -computer $_ -name netlogon }
$status=get-content List.txt | foreach { get-Service -computer $_ -name netlogon } | Select-Object status
if ($status -eq "Running") {add-content -path Online.txt -value good}
else {add-content -path Offline.txt -value $_.name}
foreach ($Computer in get-content Online.txt)
{
$admin=[adsi]("WinNT://" + $computer + "/administrator, user")
$admin.psbase.invoke("SetPassword", $NewPass )
}