$frontlineusers = Get-MsolGroupMember -GroupObjectID $frontline -All
Start-Job {
$users = $args[0]
$allusers2 = @()
$svcaccount = "<accountname>"
$admincred = GetAdminCredentials $svcaccount
Connect-msolservice -Credential $admincred
ForEach ($user in $users) {
$msuser = Get-msoluser -ObjectID $user.ObjectID
$pso = New-Object psobject
$pso | Add-Member -MemberType NoteProperty -Name DisplayName -Value $msuser.DisplayName
$pso | Add-Member -MemberType NoteProperty -Name Department -Value $msuser.Department
$pso | Add-Member -MemberType NoteProperty -Name City -Value $msuser.City
$pso | Add-Member -MemberType NoteProperty -Name FirstName -Value $msuser.FirstName
$pso | Add-Member -MemberType NoteProperty -Name LastName -Value $msuser.LastName
$pso | Add-Member -MemberType NoteProperty -Name Office -Value $msuser.Office
$pso | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value $msuser.UserPrincipalName
$pso | Add-Member -MemberType NoteProperty -Name PrimarySMTPAddress -Value $user.EmailAddress
$pso | Add-Member -MemberType NoteProperty -Name PostalCode -Value $msuser.PostalCode
$pso | Add-Member -MemberType NoteProperty -Name State -Value $msuser.State
$pso | Add-Member -MemberType NoteProperty -Name IsLicensed -Value $msuser.IsLicensed
$pso | Add-Member -MemberType NoteProperty -Name LicenseType -Value "frontline"
$pso | Add-Member -MemberType NoteProperty -Name SamAccountName -Value $msuser.SignInName.Split("@")[0]
$allusers2 += $pso
}
Return $allusers2
} -ArgumentList $frontlineusers
作业运行,但它实际上并没有连接到msol和拉用户数据,显然我不能让它返回任何东西。我一直在尝试将作业设置为一个变量,使用$users变量作为定义的参数,似乎没有任何工作。任何帮助都很感激。
1条答案
按热度按时间4xrmg8kj1#
注意事项:
Connect-msolservice
无法连接的原因。GetAdminCredentials
导致了一个交互式提示符,那么在您尝试使用Receive-Job
收集作业的输出之前,您将无法看到该提示符GetAdminCredentials
*,并在作业脚本块中将生成的凭据对象引用为$using:admincred
-ArgumentList $frontlineusers
将数组$frontlineusers
的元素 * 单独 * 作为参数传递给作业脚本块。因此,
$args[0]
仅引用 first 元素。有两种解决方案:
-ArgumentList
参数不变,并在作业脚本块中将$users = $args[0]
替换为$users = $args
。