none
Passing variable from Start-Job RRS feed

  • Question

  • Using the "Button - Start-Job" control set in Powershell studio, I'm trying to work on how to retrieve a variable I am setting in a Start-Job command, code looks like the following...

    $Job1 = @{
    		Name	  = 'Job1'
    		JobScript = {
    			Param ($global:usercred)
    			
    			$s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ServerName.domain.com/PowerShell -Credential $global:usercred -Authentication Kerberos
    			Import-Module (Import-PSSession $s -AllowClobber -DisableNameChecking) -DisableNameChecking
    			
    			$DAG07 = (Get-MailboxDatabase | where { $_.MasterServerOrAvailabilityGroup -eq "USADAG07" }).count
    			$DAG08 = (Get-MailboxDatabase | where { $_.MasterServerOrAvailabilityGroup -eq "USADAG08" }).count		
    			for ($i = 0; $i -lt 50; $i++) { Start-Sleep -Milliseconds 100 }
    			
    		}
    		ArgumentList = $global:usercred
    		CompletedScript = {
    			Param ($Job)
    			????????????
    		}
    		UpdateScript = {
    			Param ($Job)
    			
    		}
    	}

    I am not sure what to use in the CompleteScript block to call the 2 variables $DAG07 and $DAG08 from the JobScript.


    • Edited by RK-33 Tuesday, April 16, 2019 2:40 PM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:17 PM Unanswerable drive-by question
    Tuesday, April 16, 2019 1:48 PM

All replies

  • Pass variables back as a hash and retrieve them from the hash.

    @{Var1 = $somevar; Var2 = $someothervar}


    \_(ツ)_/

    Tuesday, April 16, 2019 3:07 PM