Variable Expansion
i'm working on exchange management shell script, i've got simple powershell related question. let's i've got following script:
this isn't working because get-messagetrackinglog doesn't $argsarr. $argsarr variable @ end -recipient user1@email.com -sender user2@email.com -start "2/12/2009 9:00:00 am" -end "2/12/2009 9:30:00 am" depending on how questions answered. if run:
i correct output. how script correctly recognize $argsarr variable @ end it's manually putting in arguments? thought might expansion issue , have tried using "'$($argsarr)'" , $($argsarr), didn't work. give me clue? i'm sure stupidly easy, haven't been able find solution.
$recipient = read-host "enter recipient's email address" |
$sender = read-host "enter sender's email address" |
$start = read-host "enter start date and time in the format 2/12/2009 9:00:00 am" |
$end = read-host "enter end date and time in the format 2/12/2009 9:30:00 am" |
if($recipient -ne "") |
{$recipientarr = "-recipient", $recipient |
$recipientarr_join = [string]::join(" ", $recipientarr) |
$argsarr = $recipientarr_join + " "} |
if($sender -ne "") |
{$senderarr = "-sender", $sender |
$senderarr_join = [string]::join(" ", $senderarr) |
$argsarr += $senderarr_join + " "} |
if($start -ne "") |
{$startarr = "-start", $start |
$startarr_join = [string]::join(" ", $startarr) |
$argsarr += $startarr_join + " "} |
if($end -ne "") |
{$endarr = "-end", $end |
$endarr_join = [string]::join(" ", $endarr) |
$argsarr += $endarr_join} |
get-exchangeserver | where {$_.ishubtransportserver -eq $true -or $_.ismailboxserver -eq $true} | get-messagetrackinglog $argsarr |
this isn't working because get-messagetrackinglog doesn't $argsarr. $argsarr variable @ end -recipient user1@email.com -sender user2@email.com -start "2/12/2009 9:00:00 am" -end "2/12/2009 9:30:00 am" depending on how questions answered. if run:
get-exchangeserver | where {$_.ishubtransportserver -eq $true -or $_.ismailboxserver -eq $true} | get-messagetrackinglog -recipient user1@email.com -sender user2@email.com -start "2/12/2009 9:00:00 am" ` -end "2/12/2009 9:30:00 am" |
i correct output. how script correctly recognize $argsarr variable @ end it's manually putting in arguments? thought might expansion issue , have tried using "'$($argsarr)'" , $($argsarr), didn't work. give me clue? i'm sure stupidly easy, haven't been able find solution.
invoke-expression "get-messagetrackinglog $argsarr"
Windows Server > Windows PowerShell
Comments
Post a Comment