Avatar of Albert Widjaja
Albert Widjaja
Flag for Australia asked on

Modifying PowerShell script to list Exchange server mailbox server name ?

I had this question after viewing Modifying PowerShell script to list the Exchange Server 2013 Mailbox Database white space ?.

Hi All,

Can anyone here please assist me in modifying the PowerShell script below to show the server name and the drive letter of the mailbox database ?

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODMBXCAS02-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory -ErrorAction STOP 
 
############################################################################## 
 
$whitespace  = ".\whitespace.htm" 
 
$checkrep = Test-Path ".\whitespace.htm"  
 
If ($checkrep -like "True") { 
	Remove-Item ".\whitespace.htm"  
} 
 
New-Item ".\whitespace.htm" -type file 
 
$smtphost = "owa.domain.com"  
$from = "white_space_report@Powershell.com"  
$to = "IT@domain.com" 
################################ADD HTML Content############################# 

Add-Content $whitespace "<html>"  
Add-Content $whitespace "<head>"  
Add-Content $whitespace "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"  
Add-Content $whitespace '<title>Whitespace Report</title>'  
add-content $whitespace '<STYLE TYPE="text/css">'  
add-content $whitespace  "<!--"  
add-content $whitespace  "td {"  
add-content $whitespace  "font-family: Tahoma;"  
add-content $whitespace  "font-size: 11px;"  
add-content $whitespace  "border-top: 1px solid #999999;"  
add-content $whitespace  "border-right: 1px solid #999999;"  
add-content $whitespace  "border-bottom: 1px solid #999999;"  
add-content $whitespace  "border-left: 1px solid #999999;"  
add-content $whitespace  "padding-top: 0px;"  
add-content $whitespace  "padding-right: 0px;"  
add-content $whitespace  "padding-bottom: 0px;"  
add-content $whitespace  "padding-left: 0px;"  
add-content $whitespace  "}"  
add-content $whitespace  "body {"  
add-content $whitespace  "margin-left: 5px;"  
add-content $whitespace  "margin-top: 5px;"  
add-content $whitespace  "margin-right: 0px;"  
add-content $whitespace  "margin-bottom: 10px;"  
add-content $whitespace  ""  
add-content $whitespace  "table {"  
add-content $whitespace  "border: thin solid #000000;"  
add-content $whitespace  "}"  
add-content $whitespace  "-->"  
add-content $whitespace  "</style>"  
Add-Content $whitespace  "</head>"  
Add-Content $whitespace  "<body>"  
add-content $whitespace  "<table width='100%'>"  
add-content $whitespace  "<tr bgcolor='Aliceblue'>"  
add-content $whitespace  "<td colspan='7' height='25' align='center'>"  
add-content $whitespace  "<font face='tahoma' color='#003499' size='4'><strong>Whitespace Report</strong></font>"  
add-content $whitespace  "</td>"  
add-content $whitespace  "</tr>"  
add-content $whitespace  "</table>"  
  
add-content $whitespace  "<table width='100%'>"  
Add-Content $whitespace "<tr bgcolor='BlanchedAlmond'>"  
Add-Content $whitespace  "<td width='10%' align='center'><B>Database Name</B></td>"  
Add-Content $whitespace  "<td width='10%' align='center'><B>AvailableNewMailboxSpace</B></td>"  
Add-Content $whitespace "</tr>"  

######################################################################################################## 
 
################################## White Space ################################################# 
 
$databases = Get-MailboxDatabase -Status | sort -Descending AvailableNewMailboxSpace 
foreach($Database in $databases) { 
	 Write-Host $Database.Name `t $Database.Server `t $Database.AvailableNewMailboxSpace -ForegroundColor Green  
	  
	 $machineName = $Database.Name  
	 $svcState = $Database.AvailableNewMailboxSpace 

	 Add-Content $whitespace "<tr>"  
	 Add-Content $whitespace "<td bgcolor= 'Lavendar' align=center>  <B> $machineName</B></td>"  
	 Add-Content $whitespace "<td bgcolor= 'Aquamarine' align=center><B>$svcState</B></td>"  
	 Add-Content $whitespace "</tr>"            
} 
 
############################################Close HTMl Tables######################################### 

Add-content $whitespace  "</table>"  
Add-Content $whitespace "</body>"  
Add-Content $whitespace "</html>"  

##################################################################################################### 
#############################################Send Email############################################## 
$subject = "WhiteSpace Report"  
$body = Get-Content ".\whitespace.htm"  
$smtp= New-Object System.Net.Mail.SmtpClient $smtphost  
$msg = New-Object System.Net.Mail.MailMessage $from, $to, $subject, $body  
$msg.isBodyhtml = $true  
$smtp.send($msg)  
#####################################################################################################

Open in new window


Thanks in advance.
Powershell.NET ProgrammingExchangeActive DirectoryScripting Languages

Avatar of undefined
Last Comment
Albert Widjaja

8/22/2022 - Mon
SOLUTION
Ranjithkumar Rajangam

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Albert Widjaja

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Tahir Qureshi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Albert Widjaja

ASKER
Hi Tahir,

Thanks for the reply, somehow I get this result:Email result ?
Albert Widjaja

ASKER
Is it possible to show the server name where the Mailbox DB is running ?
Albert Widjaja

ASKER
Half Working ?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck