"Initials" by "Florian Körner", licensed under "CC0 1.0". / Remix of the original. - Created with dicebear.comInitialsFlorian Körnerhttps://github.com/dicebear/dicebearPO
PowerShell ech0 1 year ago 100%

Get-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it is null.

#Install-Module -Name AzureADPreview
#Install-Module -Name ActiveDirectory
Import-Module ActiveDirectory
Import-Module AzureADPreview

$cred = Get-Credential

Connect-AzureAD -Credential $cred

$users = Get-ADUser -SearchBase ‘OU=Test Users, OU=CO Users, DC=CO ,DC=domain, DC=org’ -filter *

foreach ($user in $users)
{
    $email = $user.samaccountname + '@co.domain.org'
    $UserPrincipalName = $email

    $newemail = "SMTP:"+$email
    $mailattribute = $email
    #$DisplayName = $user.displayName
    #$sam = $_SamAccountName

    $account = Get-AzureADUser | Where-Object {$_.UserPrincipalName -eq $UserPrincipalName}
    Write-Host "UserPrincipalName: $UserPrincipalName"
    Get-AzureADUser -ObjectId $account.ObjectId | select Account }
Add-AzureADGroupMember -ObjectId (Get-AzureADGroup -SearchString "OfficeUsersTest").ObjectId -RefObjectId $account.ObjectId

This is going to be a script that runs nightly to double checkthat certain atributes have been created for new User accounts.

5
1
Comments 1