Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Using -repalce to alter content of a variable

$
0
0

The script gets each mailboxes ProhibitSendQuota but as some of the mailboxes reside on Databases with storage limits set at the database level they return “Unlimited”. As a side note, I run this on an Exchange 2010 server so I'm stuck with Powershell V2.

Add-PSSnapinMicrosoft.Exchange.Management.PowerShell.E2010

$Date=Get-Date-FormatddMMMMyyyy

$Database=get-mailboxdatabase|selectName

$Mailbox=$Database|%{

    Get-Mailbox-Database$_.Name  |Select-Objectdisplayname,ProhibitSendReceiveQuota,database 

}

$Filter=$mailbox-replace"unlimited","2.00GB"

$Filter|?{$_.Database -like"db*"}  |Export-Csv"c:\MonthlyQuotaReport.$date.csv"

 

 

The report gets emailed by the script, that line isn’t here, to the accounts department. So I wanted to change “Unlimited” to read “2.00GB” and that’s where it goes wrong.

$Mailbox is formatted all nice.

PS C:\Users\cycadmin> $mailbox

DisplayName     ProhibitSendReceiveQuota         Database

-----------              ------------------------                        --------

Nick Giles            unlimited                                             DB02                                    

Marc Bell             unlimited                                             YorkDB1 

After I apply the -replace filter the output, $filter, it goes like I hadn’t used  –ExpandProperty but is has applied the change.

PS C:\Users\cycadmin.> $filter

@{DisplayName=Nick Giles; ProhibitSendReceiveQuota=2.00GB; Database=DB021}

@{DisplayName=Marc Bell; ProhibitSendReceiveQuota=2.00GB; Database=KentkDB1}

This then means the final line doesn’t output anything as no match can be found It did before I applied the –replace command.

So how do apply the replacement to the variable and keep the formatting OK for the final line to work and produce the CSV. Also is there a better way of doing this bit

$Filter=$mailbox-replace"unlimited","2.00GB"

$Filter|?{$_.Database -like"db*"}  |Export-Csv"c:\MonthlyQuotaReport.$date.csv"

 

 

 

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles