Some PowerShell commands and syntax. Click on a command string to copy it to the clipboard.
syntax AD M365 installs/upgrades Links
Get-Alias -Definition Get-ChildItem
find all aliases for Get-ChildItem
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
list a command and which module (and version) it belongs to
list a command’s parameters
(Get-Command Get-Alias).Parameters.Keys
Get-Command Get-Alias | select Definition | fl
command history is stored in:
%USERPROFILE%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
format command output
-Verb lists all the commands beginning Format-
ft (Format-Table) truncates text if it goes off the screen
fl (Format-List) displays more information and wraps long lines
select * does a | fl by default
Get-Command Get-Alias | 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
get raw user interface (console window) info
set the size of the console window
() 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
install Microsoft Entra Connect (formerly Azure AD Connect) by downloading the installer from the Microsoft Download Center
import 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
Microsoft Graph Users Groups Calendars Resources Room Lists
Import-Module ExchangeOnlineManagement
only required if Get-Module doesn’t list ExchangeOnlineManagement
$UserCredential = Get-Credential
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $true
check the connection
disconnect from Exchange Server
Connect-MgGraph -Scopes "Directory.AccessAsUser.All", "User.ReadWrite.All", "Group.ReadWrite.All"
Microsoft Graph is the replacement for the Azure AD PowerShell and MSOnline modules
tick "Consent on behalf of your organisation" so the prompt doesn’t appear for every user
check the connection
list all current scopes
change name of user (e.g. new minibus)
Set-User minibus-SF69FYU -Name minibus-RJ74OBL
use Entra admin center to update Display name, Mail nickname (=Alias)
use Exchange admin center to delete old email addresses (lowercase smtp)
list groups
Get-MgGroup -Filter "DisplayName eq 'calendars_'"
list the members of a group
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
list modules that have been imported into the current session
list modules that are installed and available to be imported
lists modules from all locations mentioned in $env:PsModulePath
list just those modules installed using Install-Module (i.e. not native)
list module with installation path
Get-Module -Name PowerShellGet -ListAvailable | select Version,ModuleBase
install a new module
Install-Module -Name ExchangeOnlineManagement
Install-Module -Name Microsoft.Graph
Install-Module -Name Microsoft.Graph.Beta
update a module
Update-Module -Name ExchangeOnlineManagement
Update-Module -Name Microsoft.Graph
Update-Module -Name Microsoft.Graph.Beta
uninstall a module
Uninstall-Module -Name ExchangeOnlineManagement
Uninstall-Module -Name Microsoft.Graph -AllVersions
Uninstall-Module -Name Microsoft.Graph.Authentication -AllVersions
uninstall Microsoft Graph main module and then all the dependency modules
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
Search for the latest version
winget search --id Microsoft.PowerShell --exact
install the latest version
winget install --id Microsoft.PowerShell --source winget
see if PowerShell can be upgraded with WinGet
winget list --id Microsoft.PowerShell --upgrade-available
upgrade to the latest version
winget upgrade --id Microsoft.PowerShell
uninstall PowerShell
Microsoft Learn - technical resources and training
configure room finder rooms workspaces
Get-MailboxCalendarConfiguration
install the Exchange Online PowerShell module
install the Microsoft Graph PowerShell SDK
SS64 reference guide - syntax and examples for the most prevalent computing commands
Microsoft Dev Blogs - Table of Basic PowerShell Commands (lists aliases)
Microsoft 365 Scripts - Microsoft 365 scripts repository
allow only specific users to book meeting rooms
| site map / contents | website privacy |
| glossary | contact me |