Forum Replies Created
-
AuthorPosts
-
Correction:
I would like the output like below format.
Server KB TimeCreated
ServerA KB12345 xxxxxxxxxxx
ServerB KB56789 xxxxxxxxxxxThanks Rob That works.
One last question,How can I catch the error for this line of code. In case of the one of the server is offline.
I would like to catch the error for that offline server while continuing the script for the rest of the server in the list.PowerShell1$MultiSession = New-PSSession -ComputerName $ServersHi it is working.
can you explain “2>&1” part ?
December 22, 2020 at 7:13 pm in reply to: How to create multiple PSSession to exchange management shell #281969Thanks. It is working now. 🙂
December 22, 2020 at 10:19 am in reply to: How to create multiple PSSession to exchange management shell #281849Oh, thanks. It’s functioning.
I tried to add the line below and received error.Error: the term format table is not recognized as the name of a cmdlet
PowerShell123Invoke-Command -Session $MySession -ScriptBlock {Get-MailboxDatabaseCopyStatus | Select-Object Name, Status, activationpreference | Format-Table -Autosize}}Code Updated:
PowerShell1234567891011121314151617181920212223242526272829$outputBox = New-Object System.Windows.Forms.RichTextBox$outputBox.Multiline = $true$outputBox.BackColor = "#FDFEFE"$outputBox.Width = 960$outputBox.Height = 630$outputBox.ReadOnly = $true$outputBox.ScrollBars = "Both"$outputBox.WordWrap = $false$outputBox.location = new-object system.drawing.point(10, 310)$outputBox.Font = "Calibri,11,style=Bold"$Form.controls.Add($outputBox)function healthcheckinfo {$outputBox.Clear()$computers = $InputBox.lines.Split("`n")foreach ($computer in $computers) {$outputBox.AppendText($computer + ":-" + "`n")try {$RebootTime = Get-WmiObject win32_operatingsystem -ComputerName $computer -ErrorAction Stop | ForEach-Object { $_.ConvertToDateTime($_.LastBootUpTime) }$outputBox.Appendtext("Reboot time: $RebootTime`n")}catch {$outputBox.Font = "Calibri,11,style=Bold"$outputBox.SelectionColor = "#FF0000"$outputBox.Appendtext("Reboot time - Error`n")}finally {$Error.Clear()}-
This reply was modified 3 months, 1 week ago by
mrdon03.
First of all, Format-Table is used only to format output in the interactive console session.
One if the options would be to loop through your $sqlservices object and append/format every value manually using spaces new lines and tabs.
Another option would be to use RTF (Reach Text Format) codes to generate a table inside reach text box:
Hope that helps.
Hi Andy
I came out with below code. I am trying to use the first method u suggest. It is still not working.
PowerShell123456789101112131415161718192021222324252627282930313233343536373839404142434445Function sqlinfo {$outputBox.Clear()$computers = $InputBox.lines.Split("`n")foreach ($computer in $computers) {try {$outputBox.AppendText("$computer`n")$sqlservices = Get-WmiObject Win32_Service -ComputerName $computer -ErrorAction Stop | Where-Object { ($_.Displayname -like "*sql*") }$props = @{'Server Name' = $computer;'Service Name' = $sqlservices.Name;'State' = $sqlservices.StartMode}$obj = New-Object -TypeName PSCustomObject -Property $props$outputBox.AppendText("$obj`n")}catch {$outputBox.AppendText("Error`n")}finally {$Error.Clear()}}}Hi Andy,
Do you mind showing me example for the first method? loop through $sqlservices object and append/format every value manually using spaces new lines and tabs.
Thank you
September 29, 2020 at 10:02 pm in reply to: Change the font colour output that display in System.Windows.Forms.RichTextBox #259912Resolved.
PowerShell12345678910111213141516171819202122232425262728293031function pingInfo {$outputBox.Clear()$computers = $InputBox.lines.Split("`n")foreach ($computer in $computers) {if (Test-Connection $computer -Count 1 -Quiet) {$outputBox.Font = "Calibri,11,style=Bold"$outputBox.SelectionColor = "#007F00"$outputBox.AppendText("$computer is Online`n")}else {$outputBox.Font = "Calibri,11,style=Bold"$outputBox.SelectionColor = "#FF0000"$outputBox.AppendText("$computer is Offline`n")}}}September 29, 2020 at 10:01 pm in reply to: Insert your output into textbox form when button is clicked. #259909PowerShell123456789101112131415161718Thanks. This is resolvedfunction pingInfo {$outputBox.Clear()$computers = $InputBox.lines.Split("`n")foreach ($computer in $computers) {if (Test-Connection $computer -Count 1 -Quiet) {$outputBox.Font = "Calibri,11,style=Bold"$outputBox.SelectionColor = "#007F00"$outputBox.AppendText("$computer is Online`n")}else {$outputBox.Font = "Calibri,11,style=Bold"$outputBox.SelectionColor = "#FF0000"$outputBox.AppendText("$computer is Offline`n")}}}-
This reply was modified 3 months, 4 weeks ago by
mrdon03.
September 28, 2020 at 8:04 pm in reply to: Insert your output into textbox form when button is clicked. #259585Hello mrdon03,
Try something like this:
PowerShell
<textarea class=”urvanov-syntax-highlighter-plain print-no” style=”tab-size: 4; font-size: 14px !important; line-height: 18px !important; z-index: 0; opacity: 0;” readonly=”readonly” data-settings=”dblclick”>if (Test-Connection $computer -Count 1 -Quiet) {
$outputBox.AppendText(“$computer is Onlinen”)
n”)
}
else {
$outputBox.AppendText(“$computer is Offline
}</textarea>123456if (Test-Connection $computer -Count 1 -Quiet) {$outputBox.AppendText(“$computer is Onlinen”</span><span class=”crayon-sy”>)</span></div>
n”)
<div id=”urvanov-syntax-highlighter-5f72799874d13738147175-3″ class=”crayon-line”><span class=”crayon-sy”>}</span></div>
<div id=”urvanov-syntax-highlighter-5f72799874d13738147175-4″ class=”crayon-line crayon-striped-line”><span class=”crayon-st”>else</span> <span class=”crayon-sy”>{</span></div>
<div id=”urvanov-syntax-highlighter-5f72799874d13738147175-5″ class=”crayon-line”><span class=”crayon-v”>$outputBox</span><span class=”crayon-sy”>.</span><span class=”crayon-e”>AppendText</span><span class=”crayon-sy”>(</span><span class=”crayon-s”>”$computer is Offline}Hope that helps.
Thanks. Do you know how can i apply the font color as well.
For example:computer is Online – GREEN
computer is Offline – REDSeptember 28, 2020 at 8:01 am in reply to: Change the font colour output that display in System.Windows.Forms.RichTextBox #259332Code updated:
PowerShell1234567891011121314function pingInfo {$outputBox.Clear()$computers = $InputBox.lines.Split("`n")foreach ($computer in $computers) {if (Test-Connection $computer -Count 1 -Quiet) {$serveronline = "$computer is online"$outputBox.Appendtext("{0}`n" -f $serveronline)}else {$serveroffline = "$computer is offline"$outputBox.Appendtext("{0}`n" -f $serveroffline)}}} -
This reply was modified 3 months, 1 week ago by
-
AuthorPosts