JBM-Computing

PowerShell

Some PowerShell commands and syntax. Click on a command string to copy it to the clipboard.

 

() {} [] . Variables PS version AD sync ExchangeOnline Calendar permissions Resources Room Lists Links

 

Get-Help Test-Path

Get-Alias %

Get-Alias -Definition ForEach-Object

 

some aliases

$_ : $PSItem = current value in the pipe line (or current argument)

dir : Get-ChildItem

echo: Write-Output

exp : ExpandProperty

fl : Format-List

ft : Format-Table

select : Select-Object

% : foreach : ForEach-Object

? : where : Where-Object

 

format command output

Get-Command -Verb Format | ft

Get-Command Format-List | fl

Get-Command -Verb Format | select Name, DLL | ft -AutoSize -Wrap

output formats include Format-Custom, Format-Hex, Format-List, Format-Table and Format-Wide

-Wrap only works with -AutoSize

 

parentheses (), braces {}, square brackets [] and dots “.

() execute the contents of all parentheses immediately

(Get-Date -Day 31 -Month 12 -Year 2024).DayOfYear

(Get-Date) - (Get-Date -Day 1 -Month 1 -Year 2000)

( 2 + 3 ) * 5

25

() = execute this
$() = execute this first and then treat the result like a variable
@() = execute this first and then treat the result like an array

dot . returns the property - these are the same:

Get-PSProvider | select -exp Drives

(Get-PSProvider).Drives

and these are the same:

Get-PSProvider | select -exp Drives | select -exp Name

(Get-PSProvider).Drives.Name

because the Drives property contains another list containing the Name property

{} are executed when it’s their turn e.g:

IF(Test-Path C:\) {echo "yes"} else {echo "no"}

also

1,2,3 | %{Write-Host $_}

1 2 3

[] ex1 - are for array elements e.g:

$abc=[array]('a','b','c')

$abc[2]

c

the first array element is [0]

[] ex2 - search for string beginning with h or k:

Get-Service -Name [hk]* | select Name, Status

use *[hk] for ending with h or k

[] ex3 - retrieve values from a “hashtable”:

$abc=@{X='7';Y='8';Z='9'}

$abc['Z']

9

 

Variables “$”

set a variable

Set-Variable -Name abc -Value 123

is the same as

$abc=123

retrieve a variable

Get-Variable -Name abc | select -exp Value

is the same as

$abc

store the result of a command in a variable

$xyz=Get-Host

retrieve the properties of a variable (that has properties)

$xyz.UI.RawUI

list all variables in the current session

displayed without the leading $

includes all the automatic variables

Get-Variable

 

PowerShell version

PowerShell “engine version”

$PSVersionTable

$PSVersionTable.PSVersion

info about the host program (e.g. PowerShell console)

Get-Host shows the version of the PowerShell host application. This may be different from the engine version in $PSVersionTable as each represents a separate part of how PowerShell is set up

Get-Host

get raw user interface (console window) info

(Get-Host).UI.RawUI

set the size of the console window

$h=Get-Host; $win=$h.UI.RawUI.WindowSize; $win.Height=69; $win.Width=120; $h.UI.RawUI.set_WindowSize($win)

 

Active Directory Sync

install the AzureAD Sync module

Import-Module ADSync

review the current intervals AzureAD Connect uses to sync

time is UTC (= GMT) not BST

Get-ADSyncScheduler

force AzureAD Connect to sync current changes

Start-ADSyncSyncCycle -PolicyType Delta

force a complete sync

Start-ADSyncSyncCycle -PolicyType Initial

 

ExchangeOnline

connect to Exchange Server

$UserCredential = Get-Credential

Import-Module ExchangeOnlineManagement

Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true

check the connection

Get-Module

Get-AcceptedDomain

disconnect from Exchange Server

Disconnect-ExchangeOnline

change name of user (e.g. new minibus)

use Entra admin center to update Display name, Mail nickname (=Alias)

use Exchange admin center to delete old email addresses (lowercase smtp)

Set-User minibus-SF69FYU -Name minibus-RJ74OBL

 

Calendar permissions

view calendar permissions

Get-MailboxFolderPermission hall:\calendar

FolderName User AccessRights ---------- ---- ------------ Calendar Default {Reviewer} Calendar Anonymous {None} Calendar calendar-group_ {Editor}

edit calendar permissions

Set-MailboxFolderPermission -Identity hall:\calendar -User Default -AccessRights Reviewer

Add-MailboxFolderPermission -Identity hall:\calendar -User JBloggs -AccessRights Editor

Remove-MailboxFolderPermission -Identity hall:\calendar -User JBloggs

list the Default calendar AccessRights for all users

Get-Mailbox | %{Get-MailboxFolderPermission $_":\calendar"} | ?{$_.User -like "Default"} | select Identity, User, AccessRights

Identity User AccessRights -------- ---- ------------ admin:\calendar Default {Reviewer} minibus:\calendar Default {Reviewer} User:\calendar Default {AvailabilityOnly} ...

 

Resources (rooms & equipment)

list all resource mailboxes

Get-Mailbox | ?{$_.IsResource –eq 'true'} | select Name, ResourceType

resource mailboxes do not need a licence

New-Mailbox -Name hall -DisplayName hall -Room

New-Mailbox -Name minibus -DisplayName minibus -Equipment

convert user mailbox to a resource

Set-Mailbox -Identity hall -Type Room

Set-Mailbox -Identity minibus -Type Equipment

convert a resource mailbox to user

Set-Mailbox -Identity hall -Type Regular

resources must be configured with the correct timezone

Set-MailboxRegionalConfiguration -Identity hall -Language en-GB -DateFormat "dd/MM/yyyy" -TimeFormat HH:mm -TimeZone "GMT Standard Time" -LocalizeDefaultFolderName

Get-MailboxRegionalConfiguration -Identity hall

...and the correct WorkingHoursTimeZone

Set-MailboxCalendarConfiguration -Identity hall -WorkingHoursTimeZone "GMT Standard Time"

Get-MailboxCalendarConfiguration -Identity hall

populate room resource values so it appears in “Room Finder”

Room Finder uses “Room Lists” as the values for the Building filter not the Building property (for backward compatibility). Populating the Building property is recommended to ensure forward compatibility.

Set-Place -Identity hall -CountryOrRegion GB -State "West Midlands" -City Coventry -Floor 1 -FloorLabel upper -Label hall -Capacity 10 -Building school

Get-Place hall | fl

 

Room Lists

create a Room List

New-DistributionGroup -Name school -RoomList

Get-DistributionGroup -Identity school

view list of all rooms

Get-Mailbox -RecipientTypeDetails RoomMailbox -ResultSize Unlimited

add room to the Room List

Add-DistributionGroupMember -Identity school -Member hall

verify each Room List contains only the intended room mailboxes

Get-DistributionGroupMember -Identity school

 

restrict who can book room resource

Set-CalendarProcessing main-hall -BookInPolicy calendars_ -AllBookInPolicy $false

Get-CalendarProcessing main-hall | fl

to reverse the restriction

Set-CalendarProcessing main-hall -BookInPolicy @() -AllBookInPolicy $true

check who is in the BookInPolicy

((Get-CalendarProcessing main-hall).BookInPolicy | Get-Recipient ).PrimarySMTPAddress

Links

SS64 reference guide - syntax and examples for the most prevalent computing commands

Microsoft Dev Blogs - Table of Basic PowerShell Commands (lists aliases)

Microsoft Ignite - technical resources and training

configure room finder rooms workspaces

Get-DistributionGroup

Get-MailboxCalendarConfiguration

Microsoft 365 Scripts - Microsoft 365 scripts repository

allow only specific users to book meeting rooms

manage room mailbox using PowerShell

set up room finder in outlook

room finder not displaying rooms

JBM-Computing

part of J E Mynott Limited

web: www.Mynott.uk

site map / contentswebsite privacy
glossarycontact me
©2000-2025 JBM-Computing
Facebook Twitter YouTube print