Tommy
Tommy

Reputation: 97

PowerShell redirect write-warning to write-output

I'm refering to the PowerShell script located here: http://support.microsoft.com/kb/2962486/en-us

I'd like to redirect the output of write-warning to write-output for this particular piece of code:

    #Check if the computer has any local user accounts whose passwords are not going to be rolled by this script
    foreach ($User in $LocalUsers)
    {
        if ($LocalAccounts -inotcontains $User)
        {
            Write-Warning "Server: '$($TargettedServerName)' has a local account '$($User)' whos password is NOT being changed by this script"
        }
    }

The reason is that default redirection not seems to redirect Write-Warning to file, from what i read it is intended to print to console only. So applying *> or *>&1 only captures StdOut and StdErr in case of this script.

https://technet.microsoft.com/en-us/library/hh847746.aspx

Is there any other way of redirecting Write-Warning output to file?

Thanks in advance.

Upvotes: 0

Views: 2051

Answers (1)

Joey
Joey

Reputation: 354834

You can use 3> to redirect the warning stream.

Upvotes: 3

Related Questions