locked
iniatiate some powershell sessions with start-job for multiple servers RRS feed

  • Question

  • Hi, could someone please explain, hot to make some ps jobs in one time for all servers at one time.

    for now it just working for 1 server at one time.

    $NOA = get-content 'C:\Users\user\Desktop\dp.txt' # Server5.domain.net
    
    $Jobs = @()
    
     $NOA | foreach { Start-Job -Name $_ -ScriptBlock { 
     
     $cmd = "E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $($_) /ps primary.domain.net /sc DDD /q /log E:\Tools\ContentLibraryCleanup > E:\Tools\ContentLibraryCleanup\Output.txt" } -Argument $_
     
     Invoke-Expression $cmd
     
     } 
    
    d     Name            PSJobTypeName   State         HasMoreData     Location             Command                 
    --     ----            -------------   -----         -----------     --------             -------                 
    175    Server1.domain... BackgroundJob   Running       True            localhost             ...                    

    Wednesday, September 20, 2017 11:24 AM

Answers

  • $sb = { E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log E:\Tools\ContentLibraryCleanup > E:\Tools\ContentLibraryCleanup\Output.txt }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_
    }
    


    \_(ツ)_/

    • Marked as answer by TechSpark0 Tuesday, September 26, 2017 10:35 AM
    Wednesday, September 20, 2017 11:40 AM

All replies

  • $sb = { E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log E:\Tools\ContentLibraryCleanup > E:\Tools\ContentLibraryCleanup\Output.txt }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_
    }
    


    \_(ツ)_/

    • Marked as answer by TechSpark0 Tuesday, September 26, 2017 10:35 AM
    Wednesday, September 20, 2017 11:40 AM
  • $sb = { E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log E:\Tools\ContentLibraryCleanup > E:\Tools\ContentLibraryCleanup\Output.txt }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_
    }


    \_(ツ)_/

    Hi, it seems not running at all.

    #$DistributionPoints = ((Get-CMDistributionPoint -AllSite ).NetworkOSPath).trim("\\")
    
    $N = ((Get-CMDistributionPoint -DistributionPointGroupName "N").NetworkOSPath).trim("\\")
    
    
    
    CD "E:\Tools\ContentLibraryCleanup\"
    
    
    
    $scriptblock = { E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps prim.domain.net /sc DSSS /q /log E:\Tools\ContentLibraryCleanup > "E:\Tools\ContentLibraryCleanup\$($args[0]).txt" }
    
    $N | ForEach-Object {
     
     Start-Job -Name $_ -ScriptBlock $scriptblock -ArgumentList $_
    
    }

    And all marked as completed? but why?

    These jobs not able to start, because i make log file for everyone.

    System.InvalidOperationException: Another instance of the tool is already running from this machine. Please wait for it to exit.
       at Microsoft.ConfigurationManager.ContentLibraryCleanup.Program.Main(String[] args)

    ypeName   State HasM oreData Location Command
    ------------- ----- ---- -------     -------- -------
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost param($arg); E:\Tools...
    BackgroundJob Completed TRUE localhost param($arg); E:\Tools...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Running TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...
    BackgroundJob Completed TRUE localhost E:\Tools\ContentLibra...

    Thursday, September 21, 2017 11:17 AM
  • $sb = { E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log E:\Tools\ContentLibraryCleanup > E:\Tools\ContentLibraryCleanup\Output.txt }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_
    }


    \_(ツ)_/

    Hi, thank you very much, sorry for asking, im not able to find it.

    It seems 2 jops running

    Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                 
    --     ----            -------------   -----         -----------     --------             -------                 
    223    srv... BackgroundJob   Running       True            localhost             E:\Tools\ContentLibra...
    225    sr2.dansk... BackgroundJob   Running       True            localhost             E:\Tools\ContentLibra...

    but im checking log files generated with :\Tools\ContentLibraryCleanup\$($args[0]).txt" } for these different servers.

    im getting error that its not possible to run that in one time with ps jobs? could it be?

    Tuesday, September 26, 2017 9:04 AM
  • You are only running the jobs against the local system.  You need to run them remotely.

    $sb = { 
    	E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log $args[1]
    }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_, "$_.log"
    }

    Each job must use a different log file name.


    \_(ツ)_/


    • Edited by jrv Tuesday, September 26, 2017 9:24 AM
    Tuesday, September 26, 2017 9:22 AM
  • You are only running the jobs against the local system.  You need to run them remotely.

    $sb = { 
    	E:\Tools\ContentLibraryCleanup\ContentLibraryCleanup.exe /dp $args[0] /ps primary.domain.net /sc DDD /q /log $args[1]
    }
    $NOA | ForEach-Object{
    	Start-Job -Name $_ -ScriptBlock sb -ArgumentList $_, "$_.log"
    }

    Each job must use a different log file name.


    \_(ツ)_/



    Its not possible, because im facing issue with Kerberos double hop, so i would like to run some PS jobs at one time at local system. to gather data with that tool. So at one time on local system for 40 servers doesnt work?
    Tuesday, September 26, 2017 10:35 AM
  • There is no issue with double hop as long as you are not trying to use remoting inside of the job script.

    The error was because you were using the same log file for all jobs.


    \_(ツ)_/

    Tuesday, September 26, 2017 6:37 PM