Reputation: 29
I've been searching through the archives here but haven't quite found a simple (ie: something I can understand) solution to my problem. I am changing passwords on service accounts using powershell and wmi. I can change the services one at a time across all servers like so:
$Service = Get-WmiObject -Class Win32_Service -computer REMOTESERVER -filter "name='SERVICENAME'"
$service.change($null,$null,$null,$null,$null,$null,$null,"newpasswordhere")
As you can see, I can refer to whatever server I want and whatever service on that server. What I'd like to do is the following
Method invocation failed because [System.Object[]] doesn't contain a method named 'change'. At line:1 char:16 + $service.change <<<< ($null,$null,$null,$null,$null,$null,$null,"newpasswordhere") + CategoryInfo : InvalidOperation: (change:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
It works fine with only one service though
How can I enhance this script to handle these 3 additional items?
Thank you
Upvotes: 2
Views: 3138
Reputation: 667
You would want to add a loop to your above script, and you would want
param
(
[string]$File
)
$Computer = Get-Content $file
foreach ($i in $Computer){
$Service = Get-WmiObject -Class Win32_Service -computer $i -filter "name='SERVICENAME'"
$service.change($null,$null,$null,$null,$null,$null,$null,"newpasswordhere")
}
You add the Param so you can utilize this many different times, then the foreach loop will run through your code for each computer in your .txt file.
Now this only answers the first part of your question but should give you a good starting point.
Upvotes: 1