locked
Checking status of 2 services after running set-service against multiple machines RRS feed

  • Question

  • All,

    I am trying to run a script against a text file which contains a list of workstations captured in a variable ($testVDI).
    The script is working with exception to one area; checking the status after I've made the change to stop and disable the service.

    Function of the script

    runs get-service and gets status of two services, AdobeARMservice,AGSService
    Stops each service
    Sets -StartupType to disabled

    I'm having trouble with checking on service status after I've made the change.

    Here is how I have it currently working...essentailly it is two scripts, One to check and stop/disable the service and the 2nd script to run the same invoke-command to check on the service with get-service and using Select-object to grab the status/StartType.

    The area where I need help is I would like to not have to run two scripts to set the changes and then check on the status.  
    Is there a way to combine them into one???
    Is there a better way to accomplish this? 

    Invoke-Command -ComputerName $testVDI -ScriptBlock {get-Service AdobeARMservice,AGSService | Stop-Service -PassThru | Set-Service -StartupType disabled};Invoke-Command -ComputerName $testVDI -ScriptBlock {get-Service AdobeARMservice,AGSService | Select-Object Name,DisplayName,status,StartType}|ft -AutoSize

    OUTPUT
    
    AGSService      Adobe Genuine Software Integrity Service Stopped Disabled  VDITEST097.ad.firstsuncb.com   ab4a76b6-6576-4db7-8b2f-9d91e3ed4b1f
    AdobeARMservice Adobe Acrobat Update Service             Stopped Disabled  VDITEST096.ad.firstsuncb.com   e004787f-546c-42a8-8499-1838d78bdeb7
    AGSService      Adobe Genuine Software Integrity Service Stopped Disabled  VDITEST096.ad.firstsuncb.com   e004787f-546c-42a8-8499-1838d78bdeb7
    AdobeARMservice Adobe Acrobat Update Service             Stopped Disabled  VDITEST095.ad.firstsuncb.com   712e4f5e-3f04-494e-95f7-3f7df53a7f79
    AGSService      Adobe Genuine Software Integrity Service Stopped Disabled  VDITEST095.ad.firstsuncb.com   712e4f5e-3f04-494e-95f7-3f7df53a7f79
    AdobeARMservice Adobe Acrobat Update Service             Stopped Disabled  VDITEST085.ad.firstsuncb.com   39aa9de1-7cd9-47b7-ab7c-952e7c21a262
    AGSService      Adobe Genuine Software Integrity Service Stopped Disabled  VDITEST085.ad.firstsuncb.com   39aa9de1-7cd9-47b7-ab7c-952e7c21a262

    Thank you for your time,
    Rob


    Thank you for your help and time, Robert Jaudon

    Thursday, December 7, 2017 5:48 PM

Answers

  • Put both scripts into the same script block.


    \_(ツ)_/

    • Marked as answer by rcjay272 Thursday, December 7, 2017 6:22 PM
    Thursday, December 7, 2017 6:03 PM
  • You do not need to use Invoke-Command.

    get-Service AdobeARMservice, AGSService -ComputerName $testVDI | 
        Stop-Service -PassThru | 
        Set-Service -StartupType disabled -PassThru | 
        Format-Table Name, DisplayName, status, StartType -AutoSize


    \_(ツ)_/


    • Edited by jrv Thursday, December 7, 2017 6:09 PM
    • Marked as answer by rcjay272 Thursday, December 7, 2017 6:22 PM
    Thursday, December 7, 2017 6:08 PM

All replies

  • Put both scripts into the same script block.


    \_(ツ)_/

    • Marked as answer by rcjay272 Thursday, December 7, 2017 6:22 PM
    Thursday, December 7, 2017 6:03 PM
  • You do not need to use Invoke-Command.

    get-Service AdobeARMservice, AGSService -ComputerName $testVDI | 
        Stop-Service -PassThru | 
        Set-Service -StartupType disabled -PassThru | 
        Format-Table Name, DisplayName, status, StartType -AutoSize


    \_(ツ)_/


    • Edited by jrv Thursday, December 7, 2017 6:09 PM
    • Marked as answer by rcjay272 Thursday, December 7, 2017 6:22 PM
    Thursday, December 7, 2017 6:08 PM
  • JRV,

    Once again...thank you.

    That is a much easier way to accomplish the task.

    The reason I was using the invoke-command is I am querying about 600 machines and I wanted to get the task completed as quickly as possible.

    With regard to speed...Which method is best?

    Rob.


    Thank you for your help and time, Robert Jaudon

    Thursday, December 7, 2017 6:25 PM
  • If you use it as a job then it will be faster but as posted it is slower than direct access.

    $job = Invoke-Command .$script -Computer $computers -AsJob -ThrottlelLimit $numjobs
    $job | Wait-Job | Receive-Job |  
         Format-Table PsComputerName, Name, DisplayName, status, StartType -AutoSize



    \_(ツ)_/


    • Edited by jrv Thursday, December 7, 2017 6:35 PM
    Thursday, December 7, 2017 6:35 PM
  • If you use it as a job then it will be faster but as posted it is slower than direct access.

    $job = Invoke-Command .$script -Computer $computers -AsJob -ThrottlelLimit $numjobs
    $job | Wait-Job | Receive-Job |  
         Format-Table PsComputerName, Name, DisplayName, status, StartType -AutoSize



    \_(ツ)_/


    JRV,

    Thanks for the example....As you know from my previous post that you've helped me out on $jobs are an area that is unfamiliar to me.  Also...on a past note I did purchase and receive the Powershell books we spoke about. :) 

    For your example...I am trying to understand the setup and have been playing around with simple $jobs to beter understand them.  Still a bit confusing to be honest.  Please take a look at my interpretation of your example and let me know if I'm on the right track.

    		$testVDI = get-content c:\temp\AllVDI.txt
    		$numjobs = '32'
    		$script = get-Service AdobeARMservice,AGSService | Stop-Service -PassThru | Set-Service -StartupType disabled
    		$job = Invoke-Command .$script -Computer $testVDI -AsJob -ThrottlelLimit $numjobs
    		$job | Wait-Job | Receive-Job |  
    		    Format-Table PsComputerName, Name, DisplayName, status, StartType -AutoSize
    

    Thanks again for the help,

    Rob


    Thank you for your help and time, Robert Jaudon

    Friday, December 8, 2017 2:36 PM
  • Now that you have the books you should read them carefully.

    "ThrottleLimit" is an integer and doesn't use quotes it defaults to 32 so it is not needed here:

    $testVDI = get-content c:\temp\AllVDI.txt
    $scriptblock = {
        get-Service AdobeARMservice, AGSService | 
            Stop-Service -PassThru |
            Set-Service -StartupType disabled -PassThru
    }
    
    $job = Invoke-Command -ScriptBlock $scriptblock -ComputerName $testVDI -AsJob
    $job | 
        Wait-Job | 
        Receive-Job |
        Format-Table PsComputerName, Name, DisplayName, status, StartType -AutoSize

    You cannot create a script block the way you were trying to.


    \_(ツ)_/


    • Edited by jrv Friday, December 8, 2017 6:35 PM
    Friday, December 8, 2017 6:35 PM