I have a large Script that creats an Application in SCCM. One part of that script is to add the Supercedence of an Application
Due to the fact that searching for the possible Supercedence takes kinda long, i run this in a Background Job
Script-Block for Background Job $Super_func1
#$SSeed has a Part of an App Name String that is optained from the Start-job Argument
$appoldname = Get-CMApplication | where-object {$_.LocalizedDisplayName -like "*$SSeed*" } | select-object-first 1 -Property LocalizedDisplayName
Get-CMDeploymentType -ApplicationName $appoldname.LocalizedDisplayName
i start this as followed
$job = @()
$job += Start-Job -ArgumentList @($AppSupersedence) -ScriptBlock $Super_func1
after waiting for the job to finish i receive the job and want to access the AppModelName's first entry and with that info i want to run a Get-CMApplication -ModelName $Modelname It is possible that the Application has more then one Result (two Deploymenttypes) so that AppModelName has more then one Value.
Wait-Job -job $job | Out-Null
$deployment23 = receive-job -job $job -keep
But i can only access the first value with a foreach loop. that seems strange to me... so i guess i am doing something stupidly wrong
#this does not work
$result23 = Get-CMApplication -ModelName $deployment23.AppModelName(0) --> Error
#This does not work
$arrayresultme = $deployment23.AppModelName(0) --> Error
#This does work
foreach ($Modelname in $deployment23.AppModelName){
$result23 = ""
$result23 = Get-CMApplication -ModelName $Modelname
break
}
The error that i get is:
Method invocation failed because [Deserialized.IResultObject#SMS_DeploymentType] does not contain a method named "AppModelName".
any hint on why i have to use the foreach would be appreciated
In PowerShell using standard brackets will usually attempt to call a method/function.
To retrieve a value from an array you need to use square brackets as shown below:
Get-CMApplication -ModelName $deployment23.AppModelName[0]