PowerShell

Microsoft Cloud services and PowerShell

This is probably one of the most blogged topics, so this post is mostly a helper for myself; to document how to access the different Online and Cloud services from Microsoft via PowerShell.

Windows Azure Active Directory is easy

$MsolCredential = Get-Credential
Connect-MsolService -Credential $MsolCredential

Windows Azure has multiple ways of doing it, but for quick access just

Add-AzureAccount

Exchange Online is a bit longer

# Set credentials
$UserCredential = Get-Credential

# Configure Session
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

# Import Session
Import-PSSession $Session

# Prefix trick when importing Session
Import-PSSession $Session -Prefix "EO"

# Turns for example Get-Mailbox into Get-EOMailbox. Could get handy
# Exit Session
Remove-PSSession $Session

SharePoint Online is no pain at all

Connect-SPOService -Url https://contoso-admin.sharepoint.com -credential admin@contoso.com

Lync Online is more like Exchange

$credential = Get-Credential

$session = New-CsOnlineSession -Credential $credential

Import-PSSession $session

Remove-PSSession $session

Windows Azure Virtual Machine hangs in “Starting” state

Once one and then you might experience that your VM hangs with the status “Starting”.

This is really frustrating as you do not have a force power off button in the Azure GUI.

This is where PowerShell is your savior.

Open a Windows Azure PowerShell window, and connect to your subscription. The run this command

Stop-AzureVM -Name YourVMName -ServiceName YourServiceName -Force

Force is the keyword here. Give it some seconds, and the VM should stop. Now, you can try to start it again.

For more on this command, and Azure Powershell in general, visit http://msdn.microsoft.com/en-us/library/jj152831.aspx