Connect PowerShell to Office 365 cloud

We do quite a few Office 365 migrations and recently found out you can connect PowerShell to the Office 365 cloud and do quite a lot of tasks that way instead of using their web interface. This is going to make our jobs much easier. I will show you how to connect to 365 and some examples of things you can do. Some of the more powerful scripts such as user control require you to install the Office 365 sign in tool and the Microsoft Online PowerShell snap-in.

To be able to run commands that affect user accounts you must install the Microsoft Online Services Module for PowerShell which can be found here which also requires the single sign on tool located here.

To connect to Office 365 with PowerShell run the following 4 commands. You will be prompted for your account credentials.

set-executionpolicy remotesigned
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Import-PSSession $Session
To connect to the user management service issue the following
connect-msolservice
To set a users password to something you know and set them to not have to change it
Set-MsolUserPassword -UserPrincipalName CHANGETO@USERNAME -NewPassword SETTHISTOTHENEWPW -ForceChangePassword $false
To set all users to not have to change password every 90 days
Get-MsolUser | Set-MsolUser –PasswordNeverExpires $True

SBS Server 2003 Exchange ActiveSync forbidden

Recently I worked on a customer who had Exchange 2003 and a new iPhone he wanted to connect but was failing. The phone actually verified and connected but they kept get a message of cannot get mail.  Their first issue was an invalid SSL certificate but once we cleared that up the iPhone was still kicking back an error it could not get email and an android device we tested with gave a access denied error. The tool at https://www.testexchangeconnectivity.com gave the following error

An HTTP 403 forbidden response was received. The response appears to have come from Unknown. Body of the response: <body><h2>HTTP/1.1 403 Forbidden</h2></body>

I saw several suggestions for this on the web but their problem ended up being that their previous IT had configured a website on port 80 and redirected the default website to port 8082. Once we switched this back everything started working and the support tool passed all tests.

If you have additional issues this post is a good resource.

VBscript FileSystemObject copy file gives permission denied error

This is something I forget about since I don't do a lot of file copying using VBS but I figured it is good information to have out there.

Any time you are copying to a folder using VBScript your folder path needs to have the trailing \ on it or your script will try to treat your folder like a file and try to overwrite it and give a permission denied.

So while this example will not work:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\test.txt")
objFile.Copy "c:\temp", True

This one will:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\test.txt")
objFile.Copy "c:\temp\", True

Windows 7 gadgets show a white box with greater than sign

Recently had a Windows 7 user who had some desktop gadgets from MSDN that were showing up as a small white box with a greater than sign in it while other gadgets were showing up fine. The fix was surprisingly simple.

Go into the control panel, choose default programs, set program access and computer defaults, select the Microsoft Windows option and click ok. Close down the sidebar process and restart it.  Gadgets should show up normal again.

You can reset your default programs back after this.