Microsoft’s PowerShell, or PowerShell to others, is a command-line utility that is very versatile in working within the Windows and Azure Domains. When all else fails in GUI, there is usually a way to do what needs to get done through PowerShell. PowerShell is a very useful utility for scripting out administrative tasks, generating reports, changing settings on remote computers, etc.
I have not used PowerShell long and am just getting started with the versatile utility now. Even though my entire career has been based in a Windows environment, it has taken me a long time to be comfortable with the PowerShell commands. Some simple things I have done are connect to exchange and restore mailboxes and pull down some InTune reports. Some other projects I am working on are creating a GUI interface for creating AD users. This way, I won’t have to log in to a Domain Controller or use a Microsoft Management Console connection to do the work for me.
There is a lot of documentation on PowerShell on the Microsoft (MS) page, but one trick I suggest is to create small scripts to connect to your Exchange and/or Azure environment. By creating this simple script, you can simply run it and then hit the ground running versus typing this in every time. Below is an example of the script I created:
- Install-Module -Name AzureAD
- Connect-AzureAD
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
- Import-PSSession $Session
That simple script will prompt you for domain credentials. Once authenticated you will get you connected to your Azure and Exchange environments. Now you can check things like user mailbox settings and space, restore mailboxes, create Azure Accounts, Pull intune reports, etc.
Most of my scripts start with those same four commands above, then I add to it. For instance, if you add the below and us use InTune in your environment you can get a list of all iPhone and Android Devices. The output will be placed in a file called C:\Mobile.csv
- Get-MobileDevice -Filter {DeviceType -like “iPhone” -or DeviceType -like “Android” -or DeviceType -notlike “Outlook”} -SortBy DeviceType | export-csv “C:\Mobile.csv”
As you can see, utilizing a total of 5 commands I was able to get all of the Mobile devices in my company without it also containing a list of any other InTune registered devices like PCs.
PowerShell can do a whole lot more and becomes even more useful when using it with other Microsoft products like InTune, GPOs, etc.
Hopefully, this short lesson on Powershell gives a basic idea on some simple things that can be done with the utility. What are some projects or scripts you have done in PowerShell? Let us know over on Facebook or Twitter and check out our other articles here.