Skip to content

Add Export of New User Details with License Information #13826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: public
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ New-MgUser -DisplayName "John Doe" -GivenName "John" -Surname "Doe" -UserPrincip
# Create a password profile
$PasswordProfile = @{
Password = 'Password123'
}
}

# Create a table for the new users results
$results = @()

# Loop through each user in the CSV file
foreach ($user in $users) {
Expand All @@ -113,10 +116,20 @@ New-MgUser -DisplayName "John Doe" -GivenName "John" -Surname "Doe" -UserPrincip
# Assign a license to the new user
$e5Sku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq 'SPE_E5'
Set-MgUserLicense -UserId $newUser.Id -AddLicenses @{SkuId = $e5Sku.SkuId} -RemoveLicenses @()

# Get the new user's details
$newUser = Get-MgUser -UserId $newUser.Id -Property UserPrincipalName, DisplayName, LicenseDetails

# Add the new user results to the results table
$results += [PSCustomObject]@{
"User Principal Name" = $newUser.UserPrincipalName
"Display Name" = $newUser.DisplayName
"License Details" = $newUser.LicenseDetails | ForEach-Object { $_.SkuPartNumber } -join ', '
}
}

# Export the results to a CSV file
$users | Export-Csv -Path "C:\temp\NewAccountResults.csv" -NoTypeInformation
$results | Export-Csv -Path "C:\temp\NewAccountResults.csv" -NoTypeInformation
```

3. Review the output file to see the results.
Expand Down