Using PowerShell to connect to Office 365 when a proxy blocks your authentication

Sometimes PowerShell does not have access to the internet because there is a proxy in the way. This can be a problem when you are trying to update help or authenticate to a cloud service provider like Office 365.

The way to get around this is to use a session option.

$cred = Get-Credential
$proxysettings = New-PSSessionOption -ProxyAccessType IEConfig
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “” `
-Credential $Cred -Authentication Basic -AllowRedirection -SessionOption` $proxysettings Import-PSSession $Session -AllowClobber -Prefix o365

This assumes that you can browse using internet explorer and that your account has the correct access in Office 365. Also in this example I am using the prefix O365 to distinguish this session from the On premises session.



Backing up user accounts in AD with PowerShell

One way to protect your Active Directory accounts. Is to store the individual accounts as XML files.

#Collect user accounts you are interected in
$Users = GetADUser -Filter {Enabled -eq $True} `
-SearchBase “OU=CompanyUsers,DC=Company,DC=Com”
foreach($user in $Users){
get-aduser$name-Properties *|Export-Clixml”c:\temp\$name.xml”

The benefit of saving accounts as XML is that it is hierarchical and preserves data like groups. This can all be extracted when you rebuild the account.

Here is an example on how you would do that:


Installing Docker on 2016 Server

The first step is to do all the windows updates

This takes as long as it takes so if you can use an image that already has the updates use that.

install-module -Name dockermsftprovider -Repository psgallery -Force

press enter to install the nuget provider if asked.

find-package docker | install-package

after the package has been installed restart the computer and check if the service has started.

with get-service docker



Note: If you are doing this from AWS or Azure there are images that already have docker installed.


Creating my Lab domain using PowerShell

This is a script I use to Create a simple domain for lab purposes

net user administrator P@ssw0rd

Rename-Computer DC1

Install-WindowsFeature AD-Domain-Services -IncludeManagementTools

import-Module ADDSDeployment

$param = @{'CreateDnsDelegation'=$false;










Install-ADDSForest @param -SafeModeAdministratorPassword (convertTo-SecureString -AsPlainText "P@ssw0rd" -Force )

Posted in AWS

Using PowerShell to start EC2 windows Instance with a data file

This script assumes that you downloaded and installed the AWS PowerShell tools and you have access keys.

Start by creating a data file. I am using a PowerShell block that I am calling c:\temp\dataFile.txt which contains the following text.

net user administrator P@ssw0rd

Set-AWSCredentials -AccessKey AXXXXXXXXXXXXXXXXXX -SecretKey OXXXXXXXXXXXXXXXXfffffffffffffff
New-EC2Instance -ImageId ami-b6af04a0 -MinCount 1 -MaxCount 1 -InstanceType t2.nano -SecurityGroupid 'sg-fffffffff' -Region us-east-1 -SubnetId subnet-9999999 -AssociatePublicIp $true -KeyName mypem -UserDataFile C:\temp\dataFile.txt -EncodeUserData


Setting the network connection profile

On newer operating systems occasionally Windows picks up the wrong connection profile.


This can be checked by using the command:


Under Network category it can be either DomainAuthenticated , Public, or Private

If the computer is not domain joined and the connection should be private but it public you can change it with the following command:

Set-NetConnectionProfile -InterfaceIndex <index number> -NetworkCategory Private