locked
Redirect Errors and Warnings to File RRS feed

  • Question

  • Hi,

    ive got the following script part:

    ....Session, Credentials, etc...
    
    $erroractionpreference = "Stop"
    TRY
    {
    Enable-CsUser -Identity "Max Power" -Registrarpool "XXXXXXXXXXXXXXXX" -SipAddressType EmailAddress 
    sleep 5
    Set-CsUser -Identity "Max Power" –RemoteCallControlTelephonyEnabled $False  –EnterpriseVoiceEnabled $False -AudioVideoDisabled $true
    Get-CsUser -Identity "Max Power" 
    }
    Catch 
    {
    $_ | Out-File C:\Temp\errors.txt -Append
    }
    Remove-PSSession $session

    This creates a *.txt file which contains all errors on those commands. I want to add also the warnings in it, is there any way to do that in one file and in two files (errors.txt/warnings.txt)

    Thank you guys ahead!



    Wednesday, April 26, 2017 1:33 PM

Answers


  • PS C:\> help about_Redirection

    Starting in PowerShell 3.0, there are multiple redirection operators for different streams (errors, warnings, verbose, etc.).


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Friday, July 7, 2017 4:15 PM
    Wednesday, April 26, 2017 2:14 PM

All replies


  • PS C:\> help about_Redirection

    Starting in PowerShell 3.0, there are multiple redirection operators for different streams (errors, warnings, verbose, etc.).


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Friday, July 7, 2017 4:15 PM
    Wednesday, April 26, 2017 2:14 PM
  • Thanks for the response,

    i already found a command:

    ....Session, Credentials, etc...
    
    
    Enable-CsUser -Identity "Max Power" -Registrarpool "XXXXXXXXXXXXXXXX" -SipAddressType EmailAddress 2>>C:\Temp\errors.txt
    sleep 5
    Set-CsUser -Identity "Max Power" –RemoteCallControlTelephonyEnabled $False  –EnterpriseVoiceEnabled $False -AudioVideoDisabled $true 2>>C:\Temp\errors.txt
    Get-CsUser -Identity "Max Power" 2>>C:\Users\cihan.g\Desktop\errors.txt 2>>C:\Temp\errors.txt
    sleep 5
    Remove-PSSession $session

    But this one only writes the errors down, i dont know how to combine that with warnings :/

    Edit1:

    Enable-CsUser -Identity "Max Power" -Registrarpool "XXXXXXXXXXXXX" -SipAddressType EmailAddress 2>>C:\Temp\errors.txt 3>>C:\Temp\warnings.txt
    sleep 5
    Set-CsUser -Identity "Max Power" –RemoteCallControlTelephonyEnabled $False  –EnterpriseVoiceEnabled $False -AudioVideoDisabled $true 2>>C:\Temp\errors.txt 3>>C:\Temp\warnings.txt
    Get-CsUser -Identity "Max Power" 2>>C:\Temp\errors.txt 3>>C:\Temp\warnings.txt
    sleep 5
    Remove-PSSession $session

    This one also captures the errors without warnings... is it even possible to get both?

    Edit2:

    Enable-CsUser -Identity "Max Power" -Registrarpool "XXXXXXXXXXXXXXXXXXXXXXXX" -SipAddressType EmailAddress >>"C:\Temp\errors.txt" *>&1
    sleep 5
    Set-CsUser -Identity "Max Power" –RemoteCallControlTelephonyEnabled $False  –EnterpriseVoiceEnabled $False -AudioVideoDisabled $true >>"C:\Temp\errors.txt" *>&1
    Get-CsUser -Identity "Max Power" >>"C:\Temp\errors.txt" *>&1
    sleep 5
    Remove-PSSession $session
    This one gets all streams expect for warnings...

    regards 
    Cihan



    Wednesday, April 26, 2017 2:28 PM