Below are samples to connect to US Government O365 environments (GCC, GCC High and GCC DoD) using various PowerShell modules.
https://docs.microsoft.com/en-us/powershell/power-bi/overview?view=powerbi-ps
If you have not already done so, install the Power BI Admin module for PowerShell. Note that you need to run this as an administrator.
Install-Module -Name MicrosoftPowerBIMgmt
If you have already installed it, make sure to update to the latest version
Update-Module -Name MicrosoftPowerBIMgmt
To connect to a Power BI environment in a US Government O365 Environment,
# Login for GCC Moderate
Login-PowerBI -Environment USGov
# Login for GCC High
Login-PowerBI -Environment USGovHigh
# Login for GCC DoD
Login-PowerBI -Environment USGovMil
If you have not already done so, install the Azure AD Module. Note that you need to run this as an administrator.
Install-Module -Name AzureAD
If you have already installed it, make sure to update to the latest version
Update-Module -Name AzureAD
# Login for GCC Moderate
Connect-AzureAD
# Login for GCC High / GCC DoD
Connect-AzureAD -AzureEnvironmentName AzureUSGovernment
https://docs.microsoft.com/en-us/powershell/azure/active-directory/overview?view=azureadps-1.0
If you have not already done so, install the MSOnline
Module. Note that you need to run this as an administrator.
Install-Module -Name MSOnline
If you have already installed it, make sure to update to the latest version
Update-Module -Name MSOnline
Authentication examples,
# Commercial and GCC
Connect-MsolService
# GCC High and DOD
Connect-MsolService -AzureEnvironment AzureUSGovernmentCloud
Sample resetting default service plan options for the O365 E3 license,
# Set this to the actual UPN you want to run this against
$UserPrincipalName = "<INPUT_ACTUAL_UPN_HERE>";
# Lookup the E3 SKU ID in the tenant
$SKU = (Get-MsolAccountSku | where {$_.AccountSkuId -like '*E3*'}).AccountSkuId
# get all the default service plans for the E3 SKU
# this is only for troubleshooting if you want to see the individual service plans
# $ServicePlans = ((Get-MsolAccountSku | Where-Object {$_.AccountSkuId -eq $SKU}).ServiceStatus | Select-Object ServicePlan -ExpandProperty ServicePlan)
$LicOptions = New-MsolLicenseOptions -AccountSkuId $SKU
# remove the license with the existing settings
Set-MsolUserLicense -UserPrincipalName $UserPrincipalName -RemoveLicenses $SKU
# add the license back with the default service plan settings (which inlcudes power apps and power automate)
Set-MsolUserLicense -UserPrincipalName $UserPrincipalName -AddLicenses $SKU -LicenseOptions $LicOptions
https://docs.microsoft.com/en-us/power-platform/admin/powerapps-powershell
To install the Power Apps modules, run the following. Note that you need to run this as an administrator.
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
If you have already installed it, make sure to update to the latest version
Update-Module -Name Microsoft.PowerApps.Administration.PowerShell
Update-Module -Name Microsoft.PowerApps.PowerShell
Examples for GCC and GCC High below,
# Add an account in GCC Moderate
Add-PowerAppsAccount -Endpoint "usgov"
# Add an account in GCC High
Add-PowerAppsAccount -Endpoint "usgovhigh"
# Add an account in DOD
Add-PowerAppsAccount -Endpoint "dod"
Details on the PAC tool can be found below (including install steps)
https://docs.microsoft.com/en-us/powerapps/developer/data-platform/powerapps-cli
Examples to use with GCC. GCC High and DOD are not supported yet with PAC tool (as of 6/10/2021). Open GitHub issue for this below,
microsoft/powerplatform-actions#73
# GCC authentication with AAD application id and secret
pac auth create --name gcc --kind CDS --url <INPUT_ENVIRONMENT_URL> --applicationId <AAD_APP_ID> --clientSecret <AAD_APP_SECRET> --tenant <AAD_TENANT_ID> --cloud UsGov
# GCC authentication with AAD username and password
pac auth create --name gcc --kind CDS --url <INPUT_ENVIRONMENT_URL> --username <USERNAME@CONTOSO.COM> --password <PASSWORD> --cloud UsGov
# Set the user credentials
$userCredential = Get-Credential
# Setup the session (GCC Moderate)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
# Setup the session (GCC High)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.us/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
# Setup the session (GCC DoD)
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://webmail.apps.mil/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
# Import the session
Import-PSSession $Session -DisableNameChecking
# Set the UserPrincipalName
$upn = <john@contoso.com> # set this to your actual UPN
# GCC
Connect-EXOPSSession -UserPrincipalName $upn
# GCC High
Connect-EXOPSSession -UserPrincipalName $upn -ConnectionUri https://outlook.office365.us/powershell-liveid -AzureADAuthorizationEndPointUri https://login.microsoftonline.us/common
# GCC DoD
Connect-EXOPSSession -UserPrincipalName $upn -ConnectionUri https://webmail.apps.mil/powershell-liveid -AzureADAuthorizationEndPointUri https://login.microsoftonline.us/common
https://docs.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps
If you have not already done so, install the Microsoft Teams PowerShell module. Note that you need to run this as an administrator.
Install-Module -Name MicrosoftTeams
If you have already installed it, make sure to update to the latest version
Update-Module -Name MicrosoftTeams
Examples for GCC, GCC High and GCC DoD are below
# GCC
Connect-MicrosoftTeams
# GCC High
Connect-MicrosoftTeams -TeamsEnvironmentName "TeamsGCCH"
# GCC DoD
Connect-MicrosoftTeams -TeamsEnvironmentName "TeamsDOD"
Installation notes can be found on the public docs below,
https://docs.microsoft.com/en-us/powershell/microsoftgraph/installation?view=graph-powershell-1.0
Getting started notes can be found on the public docs below,
https://docs.microsoft.com/en-us/powershell/microsoftgraph/get-started?view=graph-powershell-1.0
Connecting to the Graph API with your current AAD user identity examples are below,
# GCC
Connect-MgGraph
# GCC High
Connect-MgGraph -Environment USGov
# DOD
Connect-MgGraph -Environment USGovDoD
Connecting to the Graph API with Azure Active Directory Application identities (i.e. app-only authentication) are below,
# GCC
Connect-MgGraph -ClientID YOUR_APP_ID -TenantId YOUR_TENANT_ID -CertificateName YOUR_CERT_SUBJECT
# GCC High
Connect-MgGraph -Environment USGov -ClientID YOUR_APP_ID -TenantId YOUR_TENANT_ID -CertificateName YOUR_CERT_SUBJECT
# DOD
Connect-MgGraph -Environment USGovDoD -ClientID YOUR_APP_ID -TenantId YOUR_TENANT_ID -CertificateName YOUR_CERT_SUBJECT