none
PoshRSJob not passing $computer RRS feed

  • Question

  • I have a script to check services from a list of computers:

    $winrmlist =  import-csv .\computers.csv | select-object -expandproperty computer

     Foreach ($computer in $winrmlist) {
              $winrmsvc=get-service -Computername $computer -name winrm
              $rpcsvc=get-service -computername $computer -name rpcss
              $remotereg=get-service -Computername $computer -name RemoteRegistry

                   if ($Winrmsvc.status -eq "stopped") {
                      write-host $computer $winrmsvc $winrmsvc.status -foregroundcolor red} else {
                       write-host $computer $winrmsvc $winrmsvc.status -foregroundcolor green}

                   if ($rpcsvc.status -eq "Stopped") {
                       write-host $computer $rpcsvc $rpcsvc.status -foregroundcolor red} else {
                       write-host $computer $rpcsvc $rpcsvc.status -foregroundcolor green}                  

                   if ($remotereg.status -eq "Stopped") {
                       write-host $computer $remotereg $remotereg.status -foregroundcolor red} else {
                       write-host $computer $remotereg $remotereg.status -foregroundcolor green} 

     }

    works fine for what I need but, could use some error catching.

    Anyhow, I downloaded PoshRSJob and, am just trying to understand how I could get it to work with this script.

    I tried a number of iterations of 

    $winrmlist =  import-csv .\computers.csv | select-object -expandproperty computer

    $winrmlist | forEach-object {Start-rsjob -name {$_.computer} -Scriptblock {
    Param($object)
    $winrmsvc=get-service -Computername $object -name winrm
              $rpcsvc=get-service -computername $object -name rpcss
              $remotereg=get-service -Computername $object -name RemoteRegistry

    I also tried:

    $winrmlist | forEach-object {Start-rsjob -name {$_.computer} -Scriptblock {
    Param($object)
    $winrmsvc=get-service -Computername $_ -name winrm
              $rpcsvc=get-service -computername $_ -name rpcss
              $remotereg=get-service -Computername $_-name RemoteRegistry

    I cant seem to get it to pass the $computer

    Can someone point me in the right direction?

    Thank you!

    Steve


    --------- SteveP

    Tuesday, July 16, 2019 6:48 PM

Answers

All replies

  • Don't use the computer name with a remote job.

    You do not need to remote these commands as Get-Service does its own remoting.  Why remote then try to remote back to the remote server?

    You should also read the full help for all commands you are trying to use so you know what they do and how to use them.


    \_(ツ)_/

    Tuesday, July 16, 2019 7:59 PM
    Moderator
  • So my goal here is to learn to use the PoshRSJob module which bundles runspaces into a really nice module.

    here is the github link if you would like to read it.  https://github.com/proxb/PoshRSJob

    I guess I dont see where the script is remoting to remote again. Its simply using get-service.


    Id like to use runspaces to get services on multiple computers faster instead of just synchronous and, mostly to use runspaces to run GPUPDATE /Force on multiple computers.

    Just using a foreach loop with gpupdate /force takes a very long time.

    If I can figure out how to pass a $computer variable to PoshRSJob, I can use it on many scripts that I use on a daily basis.


    --------- SteveP

    Wednesday, July 17, 2019 12:26 AM
  • Use a workflow as it will be faster and easier for you to use. Just run a parallel "foreach" loop in the workflow and it will create all of the runspaces for you with no complexity.

    Note that this is not a support forum for user designed GitHub modules or scripts.  It is a forum for scripts that you have written.  For help with the module please read the help for the GitHub module.

    help Start-rsjob -full

    Also:

    help workflow


    \_(ツ)_/

    Wednesday, July 17, 2019 12:31 AM
    Moderator
  • A big thanks to @Richard Siddaway

    I used an article he wrote and, was able to just use batches and Jobs to do what I needed.


    --------- SteveP

    Wednesday, July 17, 2019 1:04 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, July 31, 2019 7:44 AM
    Moderator
  • Here is a blog the Richard writes. It is where I was able  to get my answers

    https://richardspowershellblog.wordpress.com/2014/03/02/powershell-jobs-series/


    --------- SteveP

    • Marked as answer by speterson400 Wednesday, July 31, 2019 12:06 PM
    Wednesday, July 31, 2019 12:06 PM