Azure: Generate RDP files for multiple VMs

Today I needed to pass on the RDP files for a bunch of Azure VMs to an external developer.

Rather than manually click on the download links in the Azure Portal each time these dev VMs are re-generated, I took the PowerShell route. This was simplified by the fact that all of the VMs in question had a similar Service Name.

Here’s the two lines it took to generate the RDP files, assuming that the Azure Service name for these VMs started with ‘dev-‘, and also assuming that I’m already connected to Azure PowerShell and have the correct subscription selected:

$devVms = Get-AzureVM | Where-Object {$_.ServiceName -like 'dev-*'} 
$devVms | ForEach-Object {Get-AzureRemoteDesktopFile -Name $_.Name -LocalPath "C:\temp\dev_rdp\$($_.Name).rdp" -ServiceName $_.ServiceName}

Office 365/Azure AD: Find all users with an email address that matches a specific string

We have a lot of shared mailboxes in Office 365. Today, I needed to find a subset of those,  change their UPN, and set the FirstName and LastName attributes.

I came across this lengthy PowerShell script that someone had created years ago to find users, but the simplest way to do this is via this one line of PowerShell, once you’ve connected to Azure AD:

Get-MsolUser -MaxResults 1000 | Where-Object {($_.ProxyAddresses -like '*texttomatch*')}

An alternative method, if you’re not connected to Azure PowerShell, but are connected to Exchange Online via PowerShell, is to use Get-Mailbox:

Get-Mailbox -ResultSize 1000 | ? {$_.EmailAddresses -like '*texttomatch*'}