Powershell


How to check your Office 365 tenant for auto-forward rules   Recently updated !

Use the following steps to check for any Office 365 auto-forward rules to external email addresses.

In this blogpost I’m using Powershell to check for any existing auto-forward rules to external email addresses.

Step 1 Logon to Office 365 using Powershell

Step 2 Export the mailbox(es) that have either redirect or forwarding

This produces a list of all mailboxes that exist in the organization where the forwaring or redirect flags are enabled

Step 3 Investigate which rules are in use

Step 4 Remove the inbox rule from a specific mailbox

Step 5 Remove all the available inbox rules from all mailboxes (if you prefer)


Script to update all Azure Powershell Modules

Use this script to update all your Azure Powershell Modules to their latest versions.


Troubleshooting Visual Studio Code: language client undefined

Recently I ran into the following problem when editing Powershell scripts using Visual Studio Code ;

vscode_error1

First I tried to remove the specific extension. Go to the extenstion tab and check for installed extensions using @installed :

vscode_error4

Click the action/config wheel to uninstall the specific extension and reload and reinstall it. In my case that wasn’t the solution. I found out that the specific extension wasn’t completely removed. My solution was after removing the extension in Visual Studio Code, checking for any leftovers in %userprofile%\.vscode\extensions :

vscode_error2

After deleting the specific folder and reinstalling the extension the error was gone!

vscode_error3

 


How to enable GPEdit.msc in Windows 10 Home Edition

By default gpedit.msc is not enabled on Windows 10 Home (inclusing 7/8.1 editions). The good news it’s possible to enable this feature.

Copy the above code to a batch script / powershell and execute it with administrative rights.

After executing I advice you to reboot. After rebooting you notice that gpedit.msc is now working :


How to show (export) all devices synchronizing with your Office 365

For a MDM project I had to make an dump which users are using which devices to (active)sync with their Office 365 mailboxes. This is how I did that :

Get-Mailbox -ResultSize Unlimited | ForEach {Get-MobileDeviceStatistics -Mailbox:$_.Identity} | Select-Object @{label=”User” ; expression={$_.Identity}},DeviceModel,DeviceOS, lastsuccesssync | Export-csv F:\powershell\activesync.csv

Running the above command showed the following output (in a CSV file format):

As you can see you see the user, the device the user is using, the OS their device uses and last time that devices succesfully synchronized.

I used Excel to import the CSV and sort on LastSuccessSync.

Find out here how to connect to Office 365 using Powershell.


Powershell: Easily export your Windows Drivers

I was looking for a simple solution for me to export (and import later) my Windows driver. I already knew that Windows 2016 had a Powershell command for that but didn’t knew that it also worked for Windows Server 2012R2 and Windows 10!

Use the following command : Export-WindowsDriver -Destination “C:\Drivers\$((Get-WmiObject -Class win32_computersystem).Model)” -Online

export_drivers

Notice the exported drivers:

export_drivers2

Now you can easily import those drivers in (for example) SCCM or MDT.

 


Powershell: Start using PowerShell using PowerShell Command Builder

Microsoft TechNet site has a great site that enables you to build your own cmdlets using a web drag and drop interface.

There is support for :

image

Let’s try Office 365 :

image

You notice the drag and drop interface. First select the verb, for example Get. Click get and the send arrow. Now choose a Noun, for example Msol User:

image

After selecting the Verb and Noun you notice the other extra options. Fill them in when needed. Now hit the Copy to Clipboard button to copy the PowerShell command to your Clipboard and start using PowerShell to manage your Office 365.

You can find the site here.