Connect-AzureAD

認証されたアカウントに接続して、Active Directory コマンドレット要求を使用します。

構文

Connect-AzureAD
       [-AzureEnvironmentName <EnvironmentName>]
       [-TenantId <String>]
       [-Credential <PSCredential>]
       [-AccountId <String>]
       [-LogLevel <LogLevel>]
       [-LogFilePath <String>]
       [-InformationAction <ActionPreference>]
       [-InformationVariable <String>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-AzureAD
       [-AzureEnvironmentName <EnvironmentName>]
       -TenantId <String>
       -CertificateThumbprint <String>
       -ApplicationId <String>
       [-LogLevel <LogLevel>]
       [-LogFilePath <String>]
       [-InformationAction <ActionPreference>]
       [-InformationVariable <String>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
Connect-AzureAD
       [-AzureEnvironmentName <EnvironmentName>]
       [-TenantId <String>]
       -AadAccessToken <String>
       [-MsAccessToken <String>]
       -AccountId <String>
       [-LogLevel <LogLevel>]
       [-LogFilePath <String>]
       [-InformationAction <ActionPreference>]
       [-InformationVariable <String>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]

説明

Connect-AzureAD コマンドレットは、Azure Active Directory コマンドレット要求に使用する認証済みアカウントを接続します。

この認証済みアカウントは、Azure Active Directory コマンドレットでのみ使用できます。

例 1: PowerShell セッションをテナントに接続する

PS C:\> Connect-AzureAD -Confirm

このコマンドは、現在の PowerShell セッションを Azure Active Directory テナントに接続します。 コマンドを実行すると、接続するテナントのユーザー名とパスワードの入力を求められます。 Confirm パラメーターは、確認を求めるメッセージを表示します。

資格情報に対して多要素認証が有効になっている場合は、対話型オプションを使用してログインするか、サービス プリンシパル認証を使用する必要があります。

例 2: 変数を使用してセッションを接続する

PS C:\> $Credential = Get-Credential
PS C:\> Connect-AzureAD -Credential $Credential

最初のコマンドは、ユーザー資格情報を取得し、$Credential変数に格納します。

2 番目のコマンドは、$Credentialの資格情報を使用して現在の PowerShell セッションに接続します。

このアカウントは、組織 ID の資格情報を使用して Azure Active Directory で認証されます。 多要素認証または Microsoft アカウントの資格情報を使用して、このアカウントで Azure Active Directory コマンドレットを実行することはできません。

例 3: サービス プリンシパルとしてセッションを接続する

# Login to Azure AD PowerShell With Admin Account
Connect-AzureAD 

# Create the self signed cert
$currentDate = Get-Date
$endDate = $currentDate.AddYears(1)
$notAfter = $endDate.AddYears(1)
$pwd = "<password>"
$thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName com.foo.bar -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $notAfter).Thumbprint
$pwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath c:\temp\examplecert.pfx -Password $pwd

# Load the certificate
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate("C:\temp\examplecert.pfx", $pwd)
$keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())


# Create the Azure Active Directory Application
$application = New-AzureADApplication -DisplayName "test123" -IdentifierUris "https://test123"
New-AzureADApplicationKeyCredential -ObjectId $application.ObjectId -CustomKeyIdentifier "Test123" -StartDate $currentDate -EndDate $endDate -Type AsymmetricX509Cert -Usage Verify -Value $keyValue

# Create the Service Principal and connect it to the Application
$sp=New-AzureADServicePrincipal -AppId $application.AppId

# Give the Service Principal Reader access to the current tenant (Get-AzureADDirectoryRole)
Add-AzureADDirectoryRoleMember -ObjectId 5997d714-c3b5-4d5b-9973-ec2f38fd49d5 -RefObjectId $sp.ObjectId

# Get Tenant Detail
$tenant=Get-AzureADTenantDetail
# Now you can login to Azure PowerShell with your Service Principal and Certificate
Connect-AzureAD -TenantId $tenant.ObjectId -ApplicationId  $sp.AppId -CertificateThumbprint $thumb

このコマンドは、サービス プリンシパルとして Azure Active Directory に対してユーザーを認証します。

パラメーター

-AadAccessToken

Azure Active Directory Graph アクセス トークンを指定します。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-AccountId

アカウントの ID を指定します。 ユーザー アクセス トークンを使用して認証する場合は、ユーザーの UPN を指定する必要があります。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-ApplicationId

サービス プリンシパルのアプリケーション ID を指定します。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-AzureEnvironmentName

Azure 環境の名前を指定します。 このパラメーターの有効値は、次のとおりです。

  • AzureCloud
  • AzureChinaCloud
  • AzureUSGovernment
  • AzureGermanyCloud

既定値は AzureCloud です。

Type:EnvironmentName
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-CertificateThumbprint

このアクションを実行するアクセス許可を持つユーザー アカウントのデジタル公開キー X.509 証明書の証明書拇印を指定します。

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-Confirm

コマンドレットの実行前に確認を求めるメッセージが表示されます。

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Credential

PSCredential オブジェクトを指定します。 PSCredential オブジェクトの詳細については、「Get-Credential」と入力 Get-Help。

PSCredential オブジェクトは、組織 ID 資格情報のユーザー ID とパスワードを提供します。

Type:PSCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InformationAction

このコマンドレットが情報イベントに応答する方法を指定します。 このパラメーターの有効値は、次のとおりです。

  • 続行
  • Ignore
  • 照会
  • SilentlyContinue
  • Stop
  • [中断]
Type:ActionPreference
Aliases:infa
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-InformationVariable

情報イベント メッセージを格納する変数を指定します。

Type:String
Aliases:iv
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-LogFilePath

この PowerShell セッションのログ ファイルの書き込み先のパス。 既定の PowerShell ログ ファイルの場所から逸脱する必要がある場合は、ここで値を指定します。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-LogLevel

ログ レベルを指定します。 このパラメーターの accdeptable 値は次のとおりです。

  • Info
  • エラー
  • 警告
  • なし

既定値は [情報] です。

Type:LogLevel
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-MsAccessToken

Microsoft Graph アクセス トークンを指定します。

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-TenantId

テナントの ID を指定します。

このパラメーターを指定しない場合、アカウントはホーム テナントで認証されます。

サービス プリンシパルとして、または Microsoft アカウントを使用するときに認証するには、TenantId パラメーターを指定する必要があります。

Type:String
Aliases:Domain, TenantDomain
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-WhatIf

コマンドレットの実行時に発生する内容を示します。 このコマンドレットは実行されません。

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False