Forum Discussion

Chandra318's avatar
Chandra318
Copper Contributor
Jun 21, 2021

PowerShell script

Hi All,  Good day. I have 100 windows servers in AWS cloud. I want to check a windows service called "xxxxx" (eg.) running or exists. If exists or running, then it should be disabled. Servers list can be given input as csv file in the script. Could any one suggest PowerShell script to achieve this?

  • Chandra318 

     

    Hi Chandra, 

     

    $password = ConvertTo-SecureString "password_here" -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential ("username_here", $password )

    Invoke-Command -ComputerName remoteservername -Credential $cred -ScriptBlock {Stop-Service -Name "your_service_name"|Set-Service -Name "your_service_name" -Status stopped -StartupType disabled

     

    You can read your csv and write each line on a $var and change on remoteservername

     

  • yuzoyox's avatar
    yuzoyox
    Iron Contributor

    Chandra318 

     

    Hi Chandra, 

     

    $password = ConvertTo-SecureString "password_here" -AsPlainText -Force

    $cred = New-Object System.Management.Automation.PSCredential ("username_here", $password )

    Invoke-Command -ComputerName remoteservername -Credential $cred -ScriptBlock {Stop-Service -Name "your_service_name"|Set-Service -Name "your_service_name" -Status stopped -StartupType disabled

     

    You can read your csv and write each line on a $var and change on remoteservername

     

Resources