Asked by:
Output of Get-Process Scrambled?

Question
-
I have a short program that displays a text box that you can type in. I have been trying to have the output of what you type in the box to be saved to a file.
However, The output of the script is scrambled. Any help would be appreciated.
The original script:
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Email Recipient Form"
$objForm.Size = New-Object System.Drawing.Size(300,200)
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Add_Click({$x=$objTextBox.Text;$objForm.Close()})
$objForm.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close()})
$objForm.Controls.Add($CancelButton)
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Please enter the E-mail Recpient's information:"
$objForm.Controls.Add($objLabel)
$objTextBox = New-Object System.Windows.Forms.TextBox
$objTextBox.Location = New-Object System.Drawing.Size(10,40)
$objTextBox.Size = New-Object System.Drawing.Size(260,20)
$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
Get-Process > Email-Output.txt
$x
I am aware it is written in an old version of PowerShell.
The output:
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
78 9 2840 3372 88 3704 AccelerometerSt
78 9 2816 2604 88 0.05 3892 AccelerometerSt
154 11 2652 7740 82 1332 atieclxx
151 10 2592 7380 80 4832 atieclxx
114 8 1744 5200 37 1000 atiesrxx
101 9 6200 5648 45 2004 AvrcpService
113 11 2464 6832 59 1168 BTDevMgr
298 43 6836 18812 142 0.17 1436 BTServer
231 22 5816 17928 127 3524 BTServer
347 31 53516 74648 1022 25.69 900 chrome
992 51 52332 97724 383 16.96 5588 chrome
85 9 2932 7096 78 0.08 5600 chrome
61 8 3120 7824 71 0.02 5632 chrome
235 23 51260 56764 272 9.67 5756 chrome
208 21 31444 35364 746 0.39 5852 chrome
148 12 3420 9312 110 3744 CLMLSvc_P2G8
142 12 3336 8832 102 0.06 5116 CLMLSvc_P2G8
32 4 1084 3012 25 1740 conhost
65 8 3172 7728 68 0.17 3280 conhost
625 13 2376 4856 49 484 csrss
360 15 3224 8440 52 580 csrss
501 17 4540 11352 69 4976 csrss
121 9 8612 8572 58 1528 CxAudMsg64
333 33 26852 36140 268 3080 DPAgent
24 6 1672 3936 44 3624 DpAgent
333 33 26844 36116 268 2.85 3924 DPAgent
24 6 1684 3956 44 0.02 4840 DpAgent
127 12 4364 9700 56 260 DpCardEngine
411 48 37964 45948 589 956 DpHostW
137 15 30584 32976 149 8.99 800 dwm
95 9 4180 3812 72 3108 dwm
849 88 45080 57928 696 3148 explorer
812 51 32896 53380 261 12.93 4004 explorer
92 8 2684 6940 49 2076 HotkeyService
125 10 1948 6552 55 3024 hpqwmiex
77 8 1532 4788 37 1360 hpservice
407 42 42028 40868 616 4548 HPSupportSolutionsFrameworkService
84 10 2824 9116 88 3536 hpvstray
80 10 2840 8884 88 0.09 4240 hpvstray
0 0 0 24 0 0 Idle
640 72 73864 98288 336 3544 iexplore
643 71 22792 41052 -1794 4488 iexplore
299 23 4904 13280 96 3956 jusched
84 10 2676 6224 76 0.00 4952 jusched
60 8 1560 6136 75 3832 LHBeacon
55 8 1420 5572 65 0.05 4352 LHBeacon
886 29 11248 20252 57 636 lsass
226 7 2844 4876 19 644 lsm
114 12 2560 6232 38 2040 mDNSResponder
130 10 7008 1780 86 0.08 1540 MicTray64
133 11 7132 848 96 3260 MicTray64
75 8 2392 8044 81 0.50 5184 notepad
75 8 2392 7988 81 0.31 5524 notepad
1453 27 73072 74088 620 1.51 4788 powershell
124 12 3608 11188 92 0.14 2208 QLBController
125 11 3600 11168 91 3640 QLBController
109 14 2740 7060 66 2236 RtkBleServ
104 10 2848 7940 72 0.11 3424 RtsCM64
103 10 2796 7888 72 3512 RtsCM64
1330 45 27312 22700 196 4092 SearchIndexer
301 14 6724 12120 47 612 services
45 7 2356 5508 53 0.16 3232 SkypePlugin
35 1 544 1244 4 284 smss
328 23 9340 16108 90 1840 spoolsv
400 14 4628 10524 50 792 svchost
541 25 19584 21436 88 856 svchost
334 16 4892 8864 39 872 svchost
751 32 140020 148892 251 1060 svchost
423 30 9156 15264 95 1084 svchost
1286 54 30448 51252 187 1136 svchost
208 17 7608 13500 55 1212 svchost
530 56 32420 36576 182 1652 svchost
321 33 10668 14508 69 1908 svchost
333 20 5944 12056 78 1988 svchost
64 7 1512 4124 26 2120 svchost
59 6 1336 3912 26 2216 svchost
99 8 1956 5896 33 2332 svchost
147 14 2420 6428 34 2656 svchost
122 8 1884 5124 47 2808 svchost
98 11 2620 6292 35 2868 svchost
384 52 68048 57260 274 3952 svchost
421 14 10604 18320 112 32.14 2528 SynTPEnh
421 14 10576 18384 112 3120 SynTPEnh
209 7 1608 4736 32 2352 SynTPEnhService
21 5 1364 3656 38 1600 SynTPHelper
23 5 1380 3724 38 4068 SynTPHelper
704 0 576 22612 28 4 System
107 10 3004 7908 66 0.02 2344 taskeng
109 9 2908 7916 66 3096 taskeng
250 27 8048 13312 167 0.11 784 taskhost
279 80 38400 32848 200 1420 taskhost
58 7 1032 3572 26 2416 UIUSrv
79 8 2496 7252 56 3200 unsecapp
78 8 2532 7248 56 0.03 5220 unsecapp
59 7 1984 4812 35 2448 valWBFPolicyService
81 10 1908 4940 44 556 wininit
113 9 3116 7608 53 704 winlogon
113 9 3088 7524 53 1904 winlogon
106 9 2200 5820 33 1732 wlanext
130 9 3580 8028 34 2192 WmiPrvSE
290 15 6576 13796 79 1456 WUDFHost
All I want what is typed into the text box.
Thank you in advance, Logan
- Moved by Bill_Stewart Monday, March 12, 2018 9:38 PM This is not "fix/debug/rewrite my script for me" forum
Tuesday, February 6, 2018 6:04 PM
All replies
-
Also, I'm well aware that I am most likely using the wrong command, but if someone could point me in the right direction that would be greatTuesday, February 6, 2018 6:08 PM
-
What you are asking is very vague.
If you really want to save the contents of a textbox just output it.
$objTextBox.Text > file.txt
\_(ツ)_/
Tuesday, February 6, 2018 6:41 PM -
Thank you for your feedback!
Logan
Friday, February 9, 2018 4:47 PM -
Would I just put it at the end of the script? I put it next to the other $objTextBox Variables and it doesn't output to the text file.
Friday, February 9, 2018 7:47 PM -
Change this line near the bottom:
Get-Process > Email-Output.txt
To this:
$objTextBox.Text | out-file Email-Output.txt Get-Process | Out-File Email-Output.txt -append
It will write the user input at the top of the file, and then underneath it will list the results of 'Get-Process'.
- Edited by -Jacob- Saturday, February 10, 2018 6:54 PM
Saturday, February 10, 2018 6:53 PM