Difference between revisions of "Powershell Commands"
(→Office365) |
|||
Line 19: | Line 19: | ||
</code> | </code> | ||
− | To enable Basic Authentication you can use this script if you are a Domain or higher admin. | + | To enable Basic Authentication you can use this script if you are a Domain or higher admin and you are using the default web site. |
<code> | <code> | ||
Line 32: | Line 32: | ||
</code> | </code> | ||
− | To enable Basic Authentication you can use this script if you are a Domain or higher admin. | + | To enable Basic Authentication you can use this script if you are a Domain or higher admin and you are using the default web site. |
<code> | <code> | ||
Line 110: | Line 110: | ||
Remove-PSSession $Session | Remove-PSSession $Session | ||
</code> | </code> | ||
+ | |||
+ | ==Global Catalog== | ||
+ | Find the Global Catalog host [https://technet.microsoft.com/en-us/library/hh852293.aspx] | ||
+ | |||
+ | <code> | ||
+ | Get-ADDomainController -Discover -Service "GlobalCatalog" | ||
+ | </code> | ||
+ | |||
+ | ==Retention== | ||
+ | Set Retention of Deleted Items for 30 days (default 14). | ||
+ | |||
+ | <code> | ||
+ | Get-MailboxDatabase | Set-MailboxDatabase -DeletedItemRetention 30 | ||
+ | </code> | ||
+ | |||
+ | ==Organizational Units== | ||
+ | Get the names of all OUs in the domain. | ||
+ | |||
+ | <code> | ||
+ | Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A | ||
+ | </code> | ||
+ | |||
+ | ==Repair Mailbox== | ||
+ | There are tools to repair Exchange mailboxes [https://technet.microsoft.com/en-us/library/ff625221%28v=exchg.141%29.aspx] | ||
+ | |||
+ | For a specific mailbox | ||
+ | |||
+ | <code> | ||
+ | New-MailboxRepairRequest -Mailbox [username] -CorruptionType FolderView | ||
+ | </code> | ||
+ | |||
+ | For all mailboxes in a mailbox database | ||
+ | |||
+ | <code> | ||
+ | New-MailboxRepairRequest -Database [MailboxDatabaseName] -CorruptionType AggregateCounts | ||
+ | </code> | ||
+ | |||
+ | ==Training== | ||
+ | Script Center [https://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx] |
Revision as of 16:50, 12 October 2015
There are three command lines now.
- The original command line DOS prompt
- Powershell
- Exchange Management Shell (EMS)
Most of these will be used in the EMS.
Contents |
Basic Authentication
Retain needs Basic Authentication enabled across the system not just on one CAS.
EWS
This script shows if Basic Authentication was enabled for EWS.
Get-WebServicesVirtualDirectory | ft server,basicauthentication
To enable Basic Authentication you can use this script if you are a Domain or higher admin and you are using the default web site.
Set-WebServicesVirtualDirectory -Identity "EWS (Default Web Site)" -BasicAuthentication $true
AutoDiscover
This script shows if Basic Authentication was enabled for AutoDiscover.
Get-AutoDiscoverVirtualDirectory | ft server,basicauthentication
To enable Basic Authentication you can use this script if you are a Domain or higher admin and you are using the default web site.
Set-AutodiscoverVirtualDirectory -Identity 'autodiscover (Default Web Site)' -BasicAuthentication $true
IIS
To restart IIS from Powershell:
IISRESET
Users and Mailbox Items
A quick overview of users and how many items they have in their mailbox, this is the same as if we piped through "| FT" to format as a table.
Get-Mailbox | Get-MailboxStatistics
For more detail you can format as a list by adding "| FL" but it would be best to pipe to a file because it will provide more information then the screen can hold.
Get-Mailbox | Get-MailboxStatistics | FL > c:\stats.txt
This script will get the size of the mailboxes of the first 30 users.
Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | Select-Object DisplayName,TotalItemSize -First 30
You can even restrict it to a single user once you know which one is the largest. [1]
Get-MailboxFolderStatistics [userName] | Select Name,FolderSize,ItemsinFolder
You can move items from one folder to another [2]
Creating a Mailbox Folder Growth Map with Powershell, EWS and eDiscovery [3]
Search-Mailbox for eDiscovery [4]
Queues
An Exchange server can become bogged down if the queues cannot clear. You can see the queue status with:
Get-Queue
If there are thousands of messages (e.g. in \Unreachable) and they are not clearing then there is an issue. You can open Exchange Toolbox and in Queue Viewer delete messages. If that is not successful then you need to restart the Microsoft Exchange Edge Transport, Microsoft Exchange Mailbox Transport Delivery and/or SMTP services
Office365
Connect to Exchange Online using remote PowerShell [5]
You can use the following versions of Windows:
- Windows 8 or Windows 8.1
- Windows Server 2012 or Windows Server 2012 R2
- Windows 7 Service Pack 1 (SP1)*
- Windows Server 2008 R2 SP1*
- You need to install the Microsoft .NET Framework 4.5 or 4.5.1 and then either the Windows Management Framework 3.0 or the Windows Management Framework 4.0. For more information, see Installing the .NET Framework 4.5, 4.5.1 and Windows Management Framework 3.0 or Windows Management Framework 4.0.
To connect:
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
To disconnect:
Remove-PSSession $Session
Global Catalog
Find the Global Catalog host [6]
Get-ADDomainController -Discover -Service "GlobalCatalog"
Retention
Set Retention of Deleted Items for 30 days (default 14).
Get-MailboxDatabase | Set-MailboxDatabase -DeletedItemRetention 30
Organizational Units
Get the names of all OUs in the domain.
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A
Repair Mailbox
There are tools to repair Exchange mailboxes [7]
For a specific mailbox
New-MailboxRepairRequest -Mailbox [username] -CorruptionType FolderView
For all mailboxes in a mailbox database
New-MailboxRepairRequest -Database [MailboxDatabaseName] -CorruptionType AggregateCounts
Training
Script Center [8]