Find and Change your PowerShell Profile

The PowerShell profile, much like the profile within a Linux Shell session allows you to add/change things about the session when it starts.

Find Profile Location

By default your profile is stored within your user’s home directory on your Windows workstation, you can find where it is or where it might be by running:

$profile

Create PowerShell Profile

If your PowerShell doesn’t already exist, we can create it, and then we’ll also add

notepad $profile

You’ll be prompted to create the file (because it doesn’t exist), say “Yes”.

Let’s just add something so when we open the PowerShell console, we get a greeting:

Microsoft.PowerShell_profile.ps1

Write-Host "Welcome Back Commander....." -ForeGroundColor Green
Write-Host "Profile: $profile" -ForeGroundColor DarkGray
Write-Host

Now when opening a PowerShell session we get the following output:

Add to PowerShell Profile

Let’s say we want to add a new function our profile, so we can just call an Entra Connect Sync on our Entra Connect Sync servers, without having to manually enter all the commands:

Function Start-ADSync {
	Invoke-Command -ComputerName HybridServer -ScriptBlock {
		Import-module adsync
		Start-adsyncsynccycle -policytype delta
	}
}

Reference: https://www.reddit.com/r/PowerShell/comments/8yclh2/trying_to_do_a_startadsyncsynccycle_on_remote/

You’ll need to save your profile file, then re-open the PowerShell session, but then you can just call the Sync to start with the below.

Note your user account will need at least enough permissions on the server to be able to perform administrative tasks.

Start-ADSync

And you’ll get the output:

Leave a comment