Problem using PowerShell Expression statement

  Kiến thức lập trình

I’m trying to run the below PowerShell code to get information about accounts that have a specific Company Name in Azure AD. The below code works, except for the Expression statement to get the Manager. ID is an object, and apparently it needs to be converted to a string for use with get-mgusermanager. I’m guessing there should be some way to do -userid $($_.Id | Out-String) or something, but that doesn’t work.

get-mgbetauser -all -filter "CompanyName eq 'Global Office'" -ConsistencyLevel eventual -count test | select-object -Property DisplayName,Mail,JobTitle,Country,Id,@{Name='manager';Expression={(get-mgusermanager -userid $_.Id -property userprincipalname).userprincipalname}}

Need to convert $_.Id to a string within the confines of the Expression statement.