I am new to using Powershell, and I am using it to set up an off-boarding process at my company. I initially used the AzureAd module, but that will be deprecated soon. I am using "

Connect-AzAccount -Credential $credential" to connect. After that, I am using

“$userId = Get-AzAdUser -UserPrincipalName $LeaverEmail” to pull the user id or the Azure user. When I used this method, the $userid variable returned “Microsoft.Azure.Commands.ActiveDirectory.PSADUser.” I will attach a screenshot of the code.

e0a42ca3-e788-427e-971e-8328b595b6a6-Screen_Shot_2022-09-26_at_3.46.16_PM.png
9 Spice ups
Write-Output "The userId is $($userId.SamAccountName)"

$userId is the entire object, you want just a single property. In this case SamAccountName.

1 Spice up

Welcome to the forum! When posting code, it’s a lot easier to read if you post it vs. screenshots. You can use the </> button on the toolbar to paste in. Be sure to select PowerShell from the drop down as well.

473250fa-d6a8-4b16-87ba-2ea2f94b4384-Post-Code.png

1 Spice up

Final point, to future proof your script, MS Graph API is the way to go. I see a few references to it in your code. Here’s a few links to get you started:

Thank you so much! I will apply these tips to my runbook.