Skip to content

Instantly share code, notes, and snippets.

@bentaylorwork
Created January 24, 2017 21:08
Show Gist options
  • Save bentaylorwork/3b1e2a4318f010bcceddb77a962f6bde to your computer and use it in GitHub Desktop.
Save bentaylorwork/3b1e2a4318f010bcceddb77a962f6bde to your computer and use it in GitHub Desktop.
workflow Get-VMIdFromJobId {
param(
    [Parameter(Mandatory=$true)]
    [STRING]$VMMJobId    
    )
    #Get VMM Connection Object
    $vmmcon = Get-AutomationConnection -Name "SCVMM"
    #Construct the VMM Credential
    $securepw = ConvertTo-SecureString -AsPlainText -String $vmmcon.Password -Force
    $VMMMgmtcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $vmmcon.Username, $securepw
    $vmId = InlineScript {
$vmm = Get-SCVMMServer -ComputerName $USING:vmmcon.ComputerName -Credential $USING:VMMMgmtcred
If (!$vmm) { throw "ERROR: connecting to SCVMM Server" }
$vmIdOutput = (Get-SCJob -ID $USING:VMMjobid).ResultObjectID.Guid
return $vmIdOutput
    }
    $vmId
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment