There are many ways to verify the syntax of a Powershell script (other than running it of course), but the most simple and useful is this one:
Get-Command -Syntax 'path\to\script.ps1'
If the syntax is valid, it will simply return the name of the script. If there are errors, it will provide a detailed syntax error report.
Using Powershell, you can quickly verify the status of the replication between domain controllers in Active Directory. This can be used in monitoring to verify a healthy AD replication. This can be run on any domain controller or on another system with RSAT or ActiveDirectory Powershell module.
Get-ADReplicationPartnerMetadata -Target "$env:USERDNSDOMAIN" -Scope Domain | FT -Auto Server,LastReplication*
To see forest-wide replication, replace -Scope Domain with -Scope Forest.
With the deprecation of Internet Explorer, it is currently no longer possible to install the Exchange Online Powershell module via ECP. But you can also install the Exchange Online Powershell module via Powershell itself:
First install the dependencies:
Install-PackageProvider -Name NuGet -Force Install-Module -Name PowerShellGet -Force
Next install the Exchange Online Management module:
Install-Module -Name ExchangeOnlineManagement
With the strong increase in hackers targeting Office 365 tenants, it may be useful to see who has Global Administrator access in your tenant. This can be done either via the Office 365 Portal but also through Powershell.
Note: be sure to install the required Powershell cmdlets before attempting this.
Connect to your Office 365 tenant:
Connect-MsolService
To retrieve a list of users with the Global Administrator role, run this:
Get-MsolRoleMember -RoleObjectId $(Get-MsolRole -RoleName "Company Administrator").ObjectId | Select DisplayName,EmailAddress
You can append Export-Csv to export the list to a CSV-file.
You can use Powershell to get the block size of a Windows NTFS volume:
On newer systems:
Get-CimInstance -ClassName Win32_Volume | Select DriveLetter,Label, BlockSize | FT -AutoSize
On older systems, the Get-CimInstance may not be available, in which case you can use the (deprecated) Get-WmiObject:
Get-WmiObject -Class Win32_Volume | Select DriveLetter,Label, BlockSize | FT -AutoSize
Starting from Windows 10 Creators Fall Update, you can use VT escape sequences to colorize the output to console. You can use this to colorize columns in Format-Table, too.
A sample snippet, colorizing the output based on the contents of the "Status" field:
$somelist | FT FirstName,LastName,@{l="Status";e={ switch ($_.Status) { "OK" {$color = 92; break} "NOT OK" {$color = 91; break} default {$color = 93} } "$e[${color}m$($_.Status)${e}[0m" }}
A complete list of color codes can be found here: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
One of the most common Exchange admin tasks is setting mailbox delegations. Personally, I usually do this through EAC but once you're familiar with the Powershell counterparts, it can be quicker to use that instead. I've created this post as a reference to do just that.
In the reference below, the user "Ellen Somebody" requires access to the mailbox of "John Doe".
Send on Behalf
Set-Mailbox john.doe -GrantSendOnBehalfTo ellen.somebody
Send As
Add-ADPermission john.doe -ExtendedRights Send-As -user ellen.somebody
Full Access
Add-MailboxPermission -Identity john.doe -User ellen.somebody -AccessRights FullAccess -InheritanceType All
If you have the Exchange Management Tools installed, you can easily import the Exchange module into a standard Powershell by running the Add-PSSnapin cmdlet.
Depending on the Exchange version, the module to add is slightly different:
Exchange 2007 | Microsoft.Exchange.Management.PowerShell.Admin |
Exchange 2010 | Microsoft.Exchange.Management.PowerShell.E2010 |
Exchange 2013 | Microsoft.Exchange.Management.PowerShell.SnapIn |
If you're not sure about the version, you can also use wildcard characters:
Add-PSSnapin *Exchange*
If you don't want to install the management tools, you can also use PS remoting to remotely access the management shell from a standard Powershell.
When running Get-ReceiveConnector, the contents of the RemoteIPRanges field may be truncated if there are a lot of entries. You can "expand" the list:
Get-ReceiveConnector MyConnector | Select -expand RemoteIPRanges | FT
This will expand each of the IP range objects and FT makes sure it's nicely formatted in a table. For single addresses, you only need the LowerBound column, but if ranges have been specified, you probably want both columns.
« ‹ | November 2024 | › » | ||||
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |