Home Dashboard Directory Help
Search

New-PSSession redirect message include null character by BrianWatts


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 800355
Opened: 9/12/2013 4:02:10 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

If I connect with New-PSSession to a target that gets redirected, for example:

New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ `
    -Credential $Cred -Authentication Basic -AllowRedirection

I receive the message:

WARNING: Your connection has been redirected to the following URI:
"https://pod51036psh.outlook.com/powershell-liveid?PSVersion=3.0"

The string in quotes includes a NULL character before the closing quote.

This can cause problems if I am recording a transcript of the session which I then wish to mail out. Since nulls should not be in the body of a mail message (some mailers truncate the message at the null, others fail to see the message completely).
Details
Sign in to post a comment.
Posted by BrianWatts on 10/22/2013 at 8:04 AM
Hi Tim,

I've put the skeleton code of what I now use to mail out the transcripts in the workarounds section.
It strips any nasty nulls and then puts the transcript into a plain text message.

That null character caused all kind of strange problems! ...

Bri
Posted by StoneReavers on 10/22/2013 at 6:57 AM
Brian, Thank you for posting this. I have been fighting with an issues related to this all morning. I have an automated script processing against O365 and trying to send an email with the PowerShell transcript as the body of the email and it keeps getting truncated. The only workarounds I have found are to format the email as HTML but them you loose all formatting and it is difficult to read, or just send the transcript as an attachment (which is not convenient to read).

Thanks,

Tim
Sign in to post a workaround.
Posted by BrianWatts on 10/22/2013 at 7:59 AM
To remove the null character, I use code similar to this:


$logfile = "some-tempfile-to-store-the-transcript"
start-transcript $logfile
# Some code that includes New-PSSession
# ...
stop-transcript

$q = get-content $logfile
$q |% {
    # some code that processes each line of the transcript ... including this:
    $output += $_.replace("`0","")         # remove any NULL characters from strings
    # ...
}

$smtp = new-object net.mail.smtpclient("smtp-server.somedomain.com")
$smtp.send($mailfrom, $mailrcpt, $mailsubj, [string]::join("`n", $output))



This puts the transcript in a simple text format email.