powershell - How to remotely change a service account password on multiple servers -


i've been searching through archives here haven't quite found simple (ie: can understand) solution problem. changing passwords on service accounts using powershell , wmi. can change services 1 @ time across servers so:

$service = get-wmiobject -class win32_service -computer remoteserver -filter "name='servicename'" $service.change($null,$null,$null,$null,$null,$null,$null,"newpasswordhere") 

as can see, can refer whatever server want , whatever service on server. i'd following

  1. provide list of servers (a text file "remoteserver1,remoteserver2" or similar
  2. change password multiple services on same machine running under same credentials. able list of mutliple services using -filter "startname '%\myserviceaccount'", when try run $service.change update password, error

method invocation failed because [system.object[]] doesn't contain method named 'change'. @ line:1 char:16 + $service.change <<<< ($null,$null,$null,$null,$null,$null,$null,"newpasswordhere") + categoryinfo : invalidoperation: (change:string) [], runtimeexception + fullyqualifiederrorid : methodnotfound

it works fine 1 service though

  1. restart services if running

how can enhance script handle these 3 additional items?

thank you

you want add loop above script, , 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 param can utilize many different times, foreach loop run through code each computer in .txt file.

now answers first part of question should give starting point.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -