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-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 | 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
() 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)
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
and these are the same:
Get-PSProvider | select -exp Drives | select -exp 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
[] ex1 - are for array elements e.g:
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”:
9
set a variable
Set-Variable -Name abc -Value 123
is the same as
retrieve a variable
Get-Variable -Name abc | select -exp Value
is the same as
store the result of a command in a variable
retrieve the properties of a variable (that has properties)
list all variables in the current session
displayed without the leading $
includes all the automatic variables
PowerShell “engine version”
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 raw user interface (console window) info
set the size of the console window
install the AzureAD Sync module
review the current intervals AzureAD Connect uses to sync
time is UTC (= GMT) not BST
force AzureAD Connect to sync current changes
Start-ADSyncSyncCycle -PolicyType Delta
force a complete sync
Start-ADSyncSyncCycle -PolicyType Initial
$UserCredential = Get-Credential
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
check the connection
disconnect from Exchange Server
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
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
Identity User AccessRights -------- ---- ------------ admin:\calendar Default {Reviewer} minibus:\calendar Default {Reviewer} User:\calendar Default {AvailabilityOnly} ...
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
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.
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
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-MailboxCalendarConfiguration
Microsoft 365 Scripts - Microsoft 365 scripts repository
allow only specific users to book meeting rooms
| site map / contents | website privacy |
| glossary | contact me |