Connect-AzureAD

인증된 계정과 연결하여 Active Directory cmdlet 요청을 사용합니다.

Syntax

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>]

Description

Connect-AzureAD cmdlet은 인증된 계정을 연결하여 Azure Active Directory cmdlet 요청에 사용합니다.

이 인증된 계정은 Azure Active Directory cmdlet에서만 사용할 수 있습니다.

예제

예제 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 변수에 저장합니다.

두 번째 명령은 $Credential 자격 증명을 사용하여 현재 PowerShell 세션을 연결합니다.

이 계정은 조직 ID 자격 증명을 사용하여 Azure Active Directory에서 인증합니다. 다단계 인증 또는 Microsoft 계정 자격 증명을 사용하여 이 계정으로 Azure Active Directory cmdlet을 실행할 수 없습니다.

예제 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

cmdlet을 실행하기 전에 확인을 요청합니다.

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

이 cmdlet이 정보 이벤트에 응답하는 방법을 지정합니다. 이 매개 변수에 허용되는 값은 다음과 같습니다.

  • 계속
  • 무시
  • 문의
  • SilentlyContinue
  • 중지
  • 일시 중지됨
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

로그 수준을 지정합니다. 이 매개 변수에 사용할 수 있는 값은 다음과 같습니다.

  • 정보
  • 오류
  • 경고
  • 없음

기본값은 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

cmdlet을 실행할 경우 발생하는 일을 표시합니다. cmdlet은 실행되지 않습니다.

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