I'm trying to capture all of the console output from a packaged psf, which is now an .exe. Using try catch blocks I am able to capture errors.
What I am not able to do is capture what the script outputs to the console. This is particularly critical when using it to create Exchange and Skype accounts. I want to see all of that information b/c it is evidence of admin actions.
This is particularly painful for Exchange b/c admin actions are not captured by the event log. In this manner, someone doesn't have to query Exchange's admin log.
For regular .ps1 files, I would use the start-transcript... stop-transcript method; however, I have read that this is not usable by Sapien PowerShell studio. When I tested it just using a regular .ps1 file, it worked phenomenally. I started a transcript and robocopy moved all of the data to a text file when I put 2>&1 | Write-Output after each executed command (with an output)
Capture all Consule Output from Form and Out-File
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
ABOUT POWERSHELL Windows PowerShell (POSH) is a command-line shell and associated scripting language created by M
I'm trying to capture all of the console output from a packaged psf, which is now an .exe. Using try catch blocks I am able to capture errors.
What I am not able to do is capture what the script outputs to the console. This is particularly critical when using it to create Exchange and Skype accounts. I want to see all of that information b/c it is evidence of admin actions.
This is particularly painful for Exchange b/c admin actions are not captured by the event log. In this manner, someone doesn't have to query Exchange's admin log.
For regular .ps1 files, I would use the start-transcript... stop-transcript method; however, I have read that this is not usable by Sapien PowerShell studio. When I tested it just using a regular .ps1 file, it worked phenomenally. I started a transcript and robocopy moved all of the data to a text file when I put 2>&1 | Write-Output after each executed command (with an output)
What I am not able to do is capture what the script outputs to the console. This is particularly critical when using it to create Exchange and Skype accounts. I want to see all of that information b/c it is evidence of admin actions.
This is particularly painful for Exchange b/c admin actions are not captured by the event log. In this manner, someone doesn't have to query Exchange's admin log.
For regular .ps1 files, I would use the start-transcript... stop-transcript method; however, I have read that this is not usable by Sapien PowerShell studio. When I tested it just using a regular .ps1 file, it worked phenomenally. I started a transcript and robocopy moved all of the data to a text file when I put 2>&1 | Write-Output after each executed command (with an output)
Capture all Consule Output from Form and Out-File
I'm trying to capture all of the console output from a packaged psf, which is now an .exe. Using try catch blocks I am able to capture errors.
What I am not able to do is capture what the script outputs to the console. This is particularly critical when using it to create Exchange and Skype accounts. I want to see all of that information b/c it is evidence of admin actions.
This is particularly painful for Exchange b/c admin actions are not captured by the event log. In this manner, someone doesn't have to query Exchange's admin log.
For regular .ps1 files, I would use the start-transcript... stop-transcript method; however, I have read that this is not usable by Sapien PowerShell studio. When I tested it just using a regular .ps1 file, it worked phenomenally. I started a transcript and robocopy moved all of the data to a text file when I put 2>&1 | Write-Output after each executed command (with an output)
What I am not able to do is capture what the script outputs to the console. This is particularly critical when using it to create Exchange and Skype accounts. I want to see all of that information b/c it is evidence of admin actions.
This is particularly painful for Exchange b/c admin actions are not captured by the event log. In this manner, someone doesn't have to query Exchange's admin log.
For regular .ps1 files, I would use the start-transcript... stop-transcript method; however, I have read that this is not usable by Sapien PowerShell studio. When I tested it just using a regular .ps1 file, it worked phenomenally. I started a transcript and robocopy moved all of the data to a text file when I put 2>&1 | Write-Output after each executed command (with an output)
Re: Capture all Consule Output from Form and Out-File
You cannot output to the console from a form. Output to a console is suppressed in Windows Forms. This has nothing to do with PSS or PowerShell it is just how Windows forms work.
You can use Write-Host to the console but that cannot be captured; it can only be displayed.
You can use Write-Host to the console but that cannot be captured; it can only be displayed.
Re: Capture all Consule Output from Form and Out-File
I will include some code to clarify what I am trying to do and capture. I highlighted the lines in particular that I am trying to capture output that would go to the console if it were not suppressed.
Try
{
if ($ExchangeServer -eq "STLEXCserver")
{
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
}
else
{
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias -Database $mdb 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
}
Set-Mailbox $alias -EmailAddresses @{ Add = "$sam@ourdomain.com" } 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
Log-Write -LogPath $sLogFile -LineValue 'Success: able to create mailbox.'
[System.Windows.Forms.MessageBox]::Show('Success: able to create mailbox.')
}
Catch
{
[System.Windows.Forms.MessageBox]::Show('Error: Unable to create mailbox.')
Log-Write -LogPath $sLogFile -LineValue 'Error: Unable to create mailbox.'
Log-Write -LogPath $sLogFile -LineValue "$Error"
}
My organization is still using Exchange 2010. When creating a user, there is output that would get pushed to the console when using it as a ps1. However, as a Winform that output is suppressed. Any recommendation on how I can capture that output?
Try
{
if ($ExchangeServer -eq "STLEXCserver")
{
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
}
else
{
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias -Database $mdb 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
}
Set-Mailbox $alias -EmailAddresses @{ Add = "$sam@ourdomain.com" } 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
Log-Write -LogPath $sLogFile -LineValue 'Success: able to create mailbox.'
[System.Windows.Forms.MessageBox]::Show('Success: able to create mailbox.')
}
Catch
{
[System.Windows.Forms.MessageBox]::Show('Error: Unable to create mailbox.')
Log-Write -LogPath $sLogFile -LineValue 'Error: Unable to create mailbox.'
Log-Write -LogPath $sLogFile -LineValue "$Error"
}
My organization is still using Exchange 2010. When creating a user, there is output that would get pushed to the console when using it as a ps1. However, as a Winform that output is suppressed. Any recommendation on how I can capture that output?
Re: Capture all Consule Output from Form and Out-File
After updating my tool to Powershell Studio 2017 and compiling my code, I believe that I may have figured it out. I'll keep you posted.
Re: Capture all Consule Output from Form and Out-File
Do not do this:
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
Do this:
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 | Out-file -FilePath $sLogFile -Append
The Write-OutPut is not needed and may create issues.
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 |Write-Output | Out-file -FilePath $sLogFile -Append
Do this:
Enable-Mailbox -identity "ourdomain\$sam" -Alias $alias 2>&1 | Out-file -FilePath $sLogFile -Append
The Write-OutPut is not needed and may create issues.