14 March 2018

Enable MFA for all Office365 users at once with PowerShell

Now that Multi Factor Authentication is widely supported through all the different PowerShell modules within Office365 and Azure it's a good idea and a best practice to enable MFA for all accounts. Especially admin accounts.

So how do we do this?
After connecting to the MSOnline service with PowerShell run:

$auth = New-Object -TypeName Microsoft.Online.Administration.StrongAuthenticationRequirement            
$auth.RelyingParty = "*"            
$auth.State = "Enabled"            
$auth.RememberDevicesNotIssuedBefore = (Get-Date)            
Get-MsolUser –All | Foreach{ Set-MsolUser -UserPrincipalName $_.UserPrincipalName -StrongAuthenticationRequirements $auth}

All users are now "enabled" for MFA.
This should give you a lot of extra brownie points on your secure score rating :-)

13 March 2018

Install Office365 requirements with PowerShell - SkypeOnline - ExchangeOnline - AzureAD - SharepointOnline - Teams PowerShell modules

Updated - 29-10-2018

  • Added Teams PowerShell module
  • Added AZ Module

I came across a script by Chris Goosen to connect to all of the Office 365 services via PowerShell.
When I tried to run it errors were flying everywhere.
All of the requirements were missing on my system.

So that's what I came up with, a one stop way to get all of those requirements in one single go.
Install Office365 PowerShell Prerequisites
Downloads and installs the AzureAD, Sharepoint Online, Skype Online for Windows PowerShell

.Made by 
Edwin van brenk


Function InstallSharepointOnlinePowerShellModule() {             
$SharepointOnlinePowerShellModuleSourceURL = "https://download.microsoft.com/download/0/2/E/02E7E5BA-2190-44A8-B407-BC73CA0D6B87/SharePointOnlineManagementShell_7918-1200_x64_en-us.msi"             
$DestinationFolder = "$ENV:homedrive$env:homepath\Downloads"             
     If (!(Test-Path $DestinationFolder))             
         New-Item $DestinationFolder -ItemType Directory -Force             
Write-Host "Downloading Sharepoint Online PowerShell Module from $SharepointOnlinePowerShellModuleSourceURL"             
         Invoke-WebRequest -Uri $SharepointOnlinePowerShellModuleSourceURL -OutFile "$DestinationFolder\SharePointOnlineManagementShell_7414-1200_x64_en-us.msi" -ErrorAction STOP             
$msifile = "$DestinationFolder\SharePointOnlineManagementShell_7414-1200_x64_en-us.msi"             
$arguments = @(             
Write-Host "Attempting to install $msifile"             
         $process = Start-Process -FilePath msiexec.exe -Wait -PassThru -ArgumentList $arguments            
         if ($process.ExitCode -eq 0)             
             Write-Host "$msiFile has been successfully installed"             
             Write-Host "installer exit code  $($process.ExitCode) for file  $($msifile)"             
         Write-Host $_.Exception.Message             
# Download and Install Visual Studio C++ 2017            
$VisualStudio2017x64URL = "https://download.visualstudio.microsoft.com/download/pr/11687625/2cd2dba5748dc95950a5c42c2d2d78e4/VC_redist.x64.exe"            
Write-Host "Downloading VisualStudio 2017 C++ from $VisualStudio2017x64"             
$DestinationFolder = "$ENV:homedrive$env:homepath\Downloads"            
Invoke-WebRequest -Uri $VisualStudio2017x64URL -OutFile "$DestinationFolder\VC_redist.x64.exe" -ErrorAction STOP            
Write-Host "Attempting to install VisualStudio 2017 C++, a reboot is required!"            
Start-Process "$DestinationFolder\VC_redist.x64.exe" -ArgumentList "/passive /norestart" -Wait            
Write-Host "Attempting to install VisualStudio 2017 C++"             
# Download and Install Skype Online PowerShell module            
$SkypeOnlinePowerShellModuleSourceURL = "https://download.microsoft.com/download/2/0/5/2050B39B-4DA5-48E0-B768-583533B42C3B/SkypeOnlinePowerShell.Exe"             
$DestinationFolder = "$ENV:homedrive$env:homepath\Downloads"             
     If (!(Test-Path $DestinationFolder))             
         New-Item $DestinationFolder -ItemType Directory -Force             
Write-Host "Downloading Skype Online PowerShell Module from $SkypeOnlinePowerShellModuleSourceURL"             
Invoke-WebRequest -Uri $SkypeOnlinePowerShellModuleSourceURL -OutFile "$DestinationFolder\SkypeOnlinePowerShell.Exe" -ErrorAction STOP             
Start-Process "$ENV:homedrive$env:homepath\Downloads\SkypeOnlinePowerShell.Exe" -ArgumentList "/quiet" -Wait            
$DestinationFolder = "$ENV:homedrive$env:homepath\Downloads"            
# Register PSGallery PSprovider and set as Trusted source            
Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2/ -PublishLocation https://www.powershellgallery.com/api/v2/package/ 
-ScriptSourceLocation https://www.powershellgallery.com/api/v2/items/psscript/ -ScriptPublishLocation https://www.powershellgallery.com/api/v2/package/ -InstallationPolicy 
Trusted -PackageManagementProvider NuGet -ErrorAction SilentlyContinue            
Set-PSRepository -Name psgallery -InstallationPolicy trusted            
# Install modules from PSGallery            
Install-Module -Name AzureAD -Force
Install-Module -Name MSOnline -Force

Install-Module -Name AZ -Force
Install-Module -Name MicrosoftTeams -Force
# Manually install Exchange Online with MFA authentication support from the Exchange Online ECP            
Write-Host "Login, go to Hybrid and download the Exchange Online Powershell module"            
Start-Process https://outlook.office365.com/ecp/

12 March 2018

How to restore a private key in IIS 7.0 or IIS 8.0

The following instructions apply to Windows Server 2008 (IIS 7.0) & Windows Server 2012 (IIS 8.0). Perform the following steps to restore the private key.

Import SSL certificate into the Personal > Certificates folder
Create a Certificates snap-in in a MMC console, refer to solution SO9999.
From the top left-hand pane, expand the Certificates tree, expand the Personal folder
Right-click the Certificates sub folder and select All Tasks > Import
The Certificate Import Wizard opens. Click Next
Click Browse and then navigate to the SSL certificate file.
Click Open > Next
Ensure "Place all certificates in the following store" is selected, ensure that "Personal" is listed for the certificate store.
Click Next > Finish

Import the Intermediate Certificate into the Intermediate Certification Authorities > Certificates folder
Download the correct Intermediate CA certificate, refer to article INFO1421.
From the left pane, expand the Intermediate Certification Authorities folder
Right-click on the Certificates sub folder
Select All Tasks > Import - A Certificate Import Wizard will open.
Click Next
Click Browse and then navigate to the Intermediate CA Certificate file
Click Next
Select Place all certificates in the following store: Intermediate Certification Authorities
Click Next
Click Finish 

Restore Private Key
With the MMC console still open, select the Certificates folder inside the Personal folder in the left-hand pane.
Double-click the newly imported SSL certificate in the right-hand pane, then select the Details tab.
Scroll down and select the Thumbprint field, then select and copy the entire thumbprint (in the bottom box) to the clipboard.
Open a command prompt, then enter the following command:
certutil -repairstore my "<thumbprint>"
certutil -repairstore my "00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f"
If successful, the response will be "CertUtil: -repairstore command completed successfully"
Assign SSL certificate in IIS
Go to > Start > Administrative Tools > Internet Information Services (IIS) Manager.
From the Connections pane on the left, expand the local server, expand the Sites folder and select the web site to be secured with SSL.
From the Actions pane on the right, select the Bindings option under Edit Site.
In the Site Bindings window, select an existing https binding and click Edit. If there are no existing https bindings, click Add.
Ensure the type is set to 'https', then select the new SSL certificate from the drop down menu.
Click the View button to confirm details of the certificate.
Click OK > Close