Automagisk dokumentation av Exchange 2013 med PowerShell

Det kan f*n inte finnas nåt tråkigare än att dokumentera inställningar för hand, däremot är det riktigt kul att skriva PowerShell skript 🙂

Utöver att du slipper dokumentera för hand, så får du kvalitet på dokumentationen, samt att du givetvis schemalägger skriptet så att du varje månad skapar en ny, tänk vad skönt att kunna följa historik på förändringar!

Skriptet är skrivet för mindre miljöer med en Exchange Site, så den dokumenterar ALLA servrar som finns, har du många siter så kan du ändra get satserna så att de bara hämtar servrarna från din lokala site.

### Exchange 2013 dokumentation script
# 2014-06-03 Harri Förberg http://itharri.com
#
### Start document and set time and date

$Time = (Get-Date -Format yyyy-MM-dd)
Write-Output ”Created Date $Time” | Out-File C:\Script\ExDoc_$Time.txt
Write-Output ” ” | Out-File C:\Script\ExDoc_$Time.txt -Append

# Get Server list
Write-Output ”*** Servers ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ExchangeServer | FT -AutoSize NAME, ServerRole, Edition, AdminDisplayVersion) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Database information
Write-Output ”*** Databases ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
$dbs = Get-MailboxDatabase -Status
foreach ($db in $dbs)
{
Write-Output (($db.Name) + (” Size ” ) + ($db.DatabaseSize ) + (” Free Space in DB ”) + ($db.AvailableNewMailboxSpace)) | Out-File C:\Script\ExDoc_$Time.txt -Append
}
Write-Output (Get-MailboxDatabase | FT Name, ServerName, EdbFilePath, LogFolderPath, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota, DeletedItemRetention, MailboxRetention, IndexEnabled, CircularLoggingEnabled, WhenChanged -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Count mailboxes per DB
Write-Output ”*** Mailbox statistics ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
$collection = (Get-MailboxDatabase).Name
foreach ($item in $collection)
{
$Count = (get-mailbox -Database $item -ResultSize Unlimited).count
Write-Output ”mailboxes in $item = $Count ” | Out-File C:\Script\ExDoc_$Time.txt -Append
}
Write-Output ((”Totalt nr of mailboxes = ”) + ((get-mailbox -ResultSize Unlimited).count)) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Mobile Devices
Write-Output ”*** ActiveSync Device AccessRules ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ActiveSyncDeviceAccessRule | FT Name, Identity, QueryString, Characteristic, AccessLevel, IsValid, WhenChanged -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** ActiveSync User Statistics ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ((Get-CASMailbox -OrganizationalUnit ”OU=Accounts,OU=Data,DC=sbgstad,DC=se” –ResultSize Unlimited -Filter {HasActiveSyncDevicePartnership -eq $True}).PrimarySmtpAddress | ForEach {Get-MobileDeviceStatistics -Mailbox $_} | Group DeviceModel | Sort Count -Descending | FT Count, Name -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”See http://www.enterpriseios.com/wiki/Complete_List_of_iOS_User_Agent_Strings for User Agent Details on IOS Devices” | Out-File C:\Script\ExDoc_$Time.txt -Append

# Public Folders
Write-Output ”*** Public Folders ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-Mailbox -PublicFolder | FT Name, ServerName, RetainDeletedItemsFor, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Public Folder Statistik ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
$PFStat = ((Get-PublicFolder \ -Recurse).Count)
Write-Output ”$PFStat Publicfolders in Org” | Out-File C:\Script\ExDoc_$Time.txt -Append

# Get DAG
Write-Output ”*** DAG ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-DatabaseAvailabilityGroup | fl Name, Servers, WitnessServer, WitnessDirectory, DatabaseAvailabilityGroupIpAddresses) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-MailboxServer | ft Name, DatabaseAvailabilityGroup, AutoDatabaseMountDial, DatabaseCopyAutoActivationPolicy) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-MailboxDatabaseCopyStatus) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Exchange Connectors
Write-Output ” ” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Send Connectors ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-SendConnector | FT Name, Comment, AddressSpaces, MaxMessageSize, Port, SmartHostsString, SourceTransportServers, ProtocolLoggingLevel -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ” ” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Receive Connectors ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ReceiveConnector | FT Name, TransportRole, Fqdn, MaxRecipientsPerMessage, MaxMessageSize, Banner, PermissionGroups, ProtocolLoggingLevel -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Offline Addressbook
Write-Output ”*** Offline Addressbooks ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-OfflineAddressBook | FT Name, Versions, AddressLists, WebDistributionEnabled, LastTouchedTime, VirtualDirectories -AutoSize) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Get IIS Directories
Write-Output ”***OWA Virtual Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-OwaVirtualDirectory | FL Identity, OwaVersion, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthentication, WindowsAuthentication, DigestAuthentication, FormsAuthentication, OAuthAuthentication, AdfsAuthentication, DefaultDomain, InternalUrl, ExternalUrl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”***ECP Virtual Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-EcpVirtualDirectory | FL Identity, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthentication, WindowsAuthentication, DigestAuthentication, FormsAuthentication, OAuthAuthentication, AdfsAuthentication, DefaultDomain, InternalUrl, ExternalUrl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”***EWS Virtual Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-WebServicesVirtualDirectory | FL Identity, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthentication, WindowsAuthentication, DigestAuthentication, OAuthAuthentication, AdfsAuthentication, InternalUrl, ExternalUrl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”***EAS Virtual Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ActiveSyncVirtualDirectory | FL Identity, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthEnabled, WindowsAuthEnabled, CompressionEnabled, ClientCertAuth, InternalUrl, ExternalUrl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”***OAB Virtual Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-OabVirtualDirectory | FL Identity, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthentication, WindowsAuthentication, InternalUrl, ExternalUrl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Autodiscover Directories ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-AutodiscoverVirtualDirectory | FL Identity, InternalAuthenticationMethods, ExternalAuthenticationMethods, BasicAuthentication, WindowsAuthentication, DigestAuthentication, OAuthAuthentication, AdfsAuthentication, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Get Client Access Server & Outlook Anywhere Config
Write-Output ”*** ClientAccessServer Config ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ClientAccessServer | fl Name, OutlookAnywhereEnabled, AutoDiscoverServiceInternalUri, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Outlook Anywhere Config ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-OutlookAnywhere | fl Server, Identity, ExternalHostname, InternalHostname, SSLOffloading, IISAuthenticationMethods, ExternalClientsRequireSsl, InternalClientsRequireSsl, WhenChanged) | Out-File C:\Script\ExDoc_$Time.txt -Append

# Get Exchange Certificates
Write-Output ” ” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ”*** Exchange Certificates ***” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output ” ” | Out-File C:\Script\ExDoc_$Time.txt -Append
$cert = (Get-ExchangeServer).Name
foreach ($item in $cert)
{
Write-Output ”$item” | Out-File C:\Script\ExDoc_$Time.txt -Append
Write-Output (Get-ExchangeCertificate -Server $item) | FT Subject, Issuer, NotBefore, NotAfter | Out-File C:\Script\ExDoc_$Time.txt -Append
}

About Harri Förberg

Jag och mina kollegor utgår ifrån "Hur svårt kan det va". Och det är en bra attityd om man ska skriva på en blogg. Nyfiket och pragmatiskt kring IT frågor med fokus på Microsoft Infrastruktur. Läs mer om oss på www.forbergsit.se

Posted on juni 3, 2014, in Exchange 2013, PowerShell and tagged . Bookmark the permalink. Lämna en kommentar.

Kommentera

Fyll i dina uppgifter nedan eller klicka på en ikon för att logga in:

WordPress.com Logo

Du kommenterar med ditt WordPress.com-konto. Logga ut / Ändra )

Twitter-bild

Du kommenterar med ditt Twitter-konto. Logga ut / Ändra )

Facebook-foto

Du kommenterar med ditt Facebook-konto. Logga ut / Ändra )

Google+ photo

Du kommenterar med ditt Google+-konto. Logga ut / Ändra )

Ansluter till %s

%d bloggare gillar detta: