0 Pluspunkte 0 Minuspunkte

Wie kann ich einen Computer in Azure AD in eine neue OU verschieben? Ich habe dieses Script

# Verbindung zu Azure AD
Connect-AzureAD

# Source und Destination OU
$sourceOU = "OU=Users,DC=contoso,DC=com"
$destinationOU = "OU=NewUsers,DC=contoso,DC=com"
$userUPN = "user1@contoso.com"

try {

    $user = Get-AzureADUser -ObjectId $userUPN

    if ($user) {

        $user | Move-AzureADObject -TargetPath $destinationOU

        Write-Host "User '$($user.UserPrincipalName)' has been moved from '$sourceOU' to '$destinationOU'."

    } else {

        Write-Host "User '$userUPN' not found"

    }
} catch {
    Write-Host "Error: $_"
}

aber was nehme ich als UPN?

von  

1 Antwort

0 Pluspunkte 0 Minuspunkte

Statt Get-AzureADUser nimmst du Get-AzureADDevice mit einem Filter für das Attribut 'DisplayName'.

Connect-AzureAD
$sourceOU = "OU=Computers,DC=contoso,DC=com"
$destinationOU = "OU=NewComputers,DC=contoso,DC=com"
$computerName = "Computer1"

try {

    $computer = Get-AzureADDevice -Filter "DisplayName eq '$computerName'"

    if ($computer) {

        $computer | Move-AzureADObject -TargetPath $destinationOU

        Write-Host "Computer '$($computer.DisplayName)' has been moved from '$sourceOU' to '$destinationOU'."

    } else {

        Write-Host "Computer with name '$computerName' not found."

    }
} catch {

    Write-Host "An error occurred: $_"

}
von