Verouderde scripts uitvoeren in de compatibiliteitsmodus

In dit artikel leert u hoe u verouderde Azure AD PowerShell-scripts uitvoert in Microsoft Entra PowerShell met behulp van de compatibiliteitsmodus, waardoor naadloze scriptmigratie met minimale wijzigingen mogelijk is. Met dit proces kunt u soepel overstappen naar de nieuwe module terwijl u bestaande automatiseringswerkstromen onderhoudt, waardoor de efficiëntie en naleving van bijgewerkte hulpprogramma's behouden blijven.

Microsoft Entra PowerShell heeft meer dan 98% compatibiliteit met Azure AD PowerShell-module. In de compatibiliteitsmodus kunt u uw bestaande Azure AD PowerShell-scripts uitvoeren met minimale wijzigingen met behulp van Microsoft Entra PowerShell met behulp van de Enable-EntraAzureADAlias opdracht. Gebruik de cmdlettoewijzing van Azure AD PowerShell naar Microsoft Entra PowerShell om equivalenten van Azure AD PowerShell- en MSOnline-cmdlets in Microsoft Entra PowerShell te vinden.

Compatibiliteitsmodus gebruiken met Enable-EntraAzureADAlias

De Enable-EntraAzureADAlias cmdlet schakelt de compatibiliteitsmodus in via aliassen. Enable-EntraAzureADAlias Standaard worden alleen compatibiliteitsaliassen ingeschakeld voor de huidige Microsoft Entra PowerShell-sessie. Zie de referentiedocumentatie Enable-EntraAzureADAlias voor meer informatie.

Als u Microsoft Entra PowerShell wilt gebruiken met uw bestaande AzureAD PowerShell-scripts, vervangt u de Connect-AzureAD opdracht door de drie opgegeven regels. Deze drie regels vormen het begin van uw gemigreerde AzureAD PowerShell-script.

Import-Module -Name Microsoft.Entra.Applications
Connect-Entra -Scopes 'Application.Read.All' #Replaces Connect-AzureAD for auth
Enable-EntraAzureADAlias #enable aliasing
Get-AzureADApplication -Top 2

Example

In dit voorbeeld voert u een script uit waarmee apps met verlopende geheimen worden geëxporteerd met behulp van Microsoft Entra PowerShell. In dit voorbeeld wordt ervan uitgegaan dat de Microsoft Entra PowerShell-module al is geïnstalleerd.

Het volgende voorbeeldscript is het oorspronkelijke AzureAD PowerShell-script.

Connect-AzureAD
$applications = Get-AzureADApplication -All $true
$Logs = @()
Write-Host "I would like to see the Applications with the Secrets and Certificates that expire in the next X amount of Days? <<Replace X with the number of days. The answer should be ONLY in Numbers>>" -ForegroundColor Green
$Days = Read-Host

Write-Host "Would you like to see Applications with already expired secrets or certificates as well? <<Answer with [Yes] [No]>>" -ForegroundColor Green
$alreadyExpired = Read-Host

$now = Get-Date

foreach ($app in $applications) {
    $appName = $app.DisplayName
    $appID = $app.objectid
    $applID = $app.AppId
    $appCreds = Get-AzureADApplication -ObjectId $appID | Select-Object -Property PasswordCredentials, KeyCredentials
    $secret = $appCreds.PasswordCredentials
    $cert = $appCreds.KeyCredentials

Opmerking: Dit codefragment wordt ingekort voor leesbaarheid. Zie het volledige voorbeeld voor meer informatie.

Als u uw script wilt gebruiken met de Microsoft Entra PowerShell-module, vervangt u de Connect-AzureAD cmdlet door de drie regels in het fragment. U hoeft het hele script niet opnieuw te schrijven.

Het volgende script is het gemigreerde script.

Import-Module -Name Microsoft.Entra.Users
Connect-Entra #Replaces Connect-AzureAD for auth
Enable-EntraAzureADAlias #Activate aliasing

$applications = Get-AzureADApplication -All $true
$logs = @()
Write-Host "I would like to see the Applications with the Secrets and Certificates that expire in the next X amount of Days? <<Replace X with the number of days. The answer should be ONLY in Numbers>>" -ForegroundColor Green
$days = Read-Host
Write-Host "Would you like to see Applications with already expired secrets or certificates as well? <<Answer with [Yes] [No]>>" -ForegroundColor Green
$alreadyExpired = Read-Host
$now = Get-Date
foreach ($app in $applications) {
    $appName = $app.DisplayName
    $appID = $app.Objectid
    $applID = $app.AppId
    $appCreds = Get-AzureADApplication -ObjectId $appID | Select-Object -Property PasswordCredentials, KeyCredentials
    $secret = $appCreds.PasswordCredentials
    $cert = $appCreds.KeyCredentials

Opmerking: Dit codefragment wordt ingekort voor leesbaarheid. Zie het volledige gewijzigde voorbeeld voor meer informatie.

Compatibiliteit testen met Test-EntraScript opdracht

De cmdlet Test-EntraScript controleert of een script met Azure AD PowerShell-opdrachten werkt met de Microsoft Entra PowerShell-module. Als er compatibiliteitsproblemen zijn, worden deze vermeld, inclusief het regelnummer, het probleemtype, de incompatibele opdracht en het specifieke codefragment.

Bekende problemen

Wanneer u migreert van de Azure AD PowerShell-module naar Microsoft Entra PowerShell, kunnen er verschillende bekende problemen optreden.

  • De parameter -Filter werkt mogelijk niet correct.
  • De parameter -SearchString werkt mogelijk niet correct.
  • Uitvoerobjecten kunnen enigszins verschillen met AzureAD-uitvoerobjecten.