Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell pipeline input breaks script

$
0
0

I've got a script that accepts either a string (in the form of a user's sAMAccount name), or the output of the Get-Mailbox (Exchange 2010) cmdlet. It takes the specified users and moves their mailboxes between Exchange databases and works great. 

Now I'm trying to add a check to make sure the target database doesn't have a smaller quota limit than the source mailbox. When I add my check, I'm not getting the expected results.

Here is the output from a run, that worked as expected:

[PS] C:\>.\test.ps1 -SamAccountName jdoe
Hi.
@{IssueWarningQuota=1.899 GB (2,039,480,320 bytes); ProhibitSendQuota=2 GB (2,147,483,648 bytes); ProhibitSendReceiveQuo ta=2.3 GB (2,469,396,480 bytes); EdbFilePath=P:\tempdb\tempdb.edb; LogFolderPath=D:\Logs\tempdb}

Here is the output that doesn't work:

[PS] C:\>Get-Mailbox jdoe | .\test.ps1
Hi.

Not the blank line, where the databases's properties should be. Here is the relevant code:

[CmdletBinding()]
param(
    [ValidateSet("ArchiveOnly","PrimaryOnly","Both")]
    [string]$MailboxMoveType = 'primaryonly',

    [string]$TargetMailboxDatabase = 'tempdb',

    [Parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)]
    [string[]]$SamAccountName

)

Begin {
    If ($MailboxMoveType -eq "PrimaryOnly") {
        If (!$TargetMailboxDatabase) {$TargetMailboxDatabase = Read-Host "Please enter the target database name"}
        $moveAttributes = @{PrimaryOnly = $True; TargetDatabase = $TargetMailboxDatabase}
        $primaryTargetProperties = Get-MailboxDatabase $TargetMailboxDatabase | select IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,EdbFilePath,LogFolderPath
        write-host 'Hi.'
        write-host $primaryTargetProperties
    }
}
Process { 
	Foreach ($user in $SamAccountName) {
        #do stuff
    }
}

Please note that, before adding the line "$primaryTargetProperties = Get-MailboxDatabase $TargetMailboxDatabase | select IssueWarningQuota,ProhibitSendQuota,ProhibitSendReceiveQuota,EdbFilePath,LogFolderPath", the script worked great when run like this: Get-Mailbox jdoe | .\test.ps1...required parameters...

I don't see any connection between the $SamAccountName and $primaryTargetProperties variables, so I don't have any idea what's going on here. Thoughts? 

Thanks.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>