1

in my powershell script a lot of items are getting printed in the console. I want to copy them and validate a data is present or not. Any way I can do it?

I am yet to get any solution for this. thank you in advance

  • Why not just do a logic check for each line written, and decide to catch whatever you choose in real time? Any controlled output can be written to the screen and to a file in real-time using the ```Tee-Object``` cmdlet or other logging methods. As others have mentioned, you can just use PS transcription, and review/parse that log after your code is complete. – postanote Jan 15 '23 at 20:48

4 Answers4

2

One Way to record everything thats going on with your Script is Powershell Transcript

Or you can just Copy the Output from your Console to a Text file in Notepad++ or something like that...

But to be honest I don't quite understand what you are trying to achieve with that, wouldn't be the goal with a script that you don't have to check something like that?

My suggestion would be that you look for a way to validate anything you need within your Script, and maybe implement some sort of Logging to have the Option to review it when something has gone wrong...

Noctran
  • 21
  • 3
2

I used $variable = command and it is working.

lemon
  • 14,875
  • 6
  • 18
  • 38
1

if your case is to validate your logs I suggest saving the logs into a file and then validating them and don't use the console for that purpose. if you still want to copy them from the console try this: Copy text from a Windows CMD window to clipboard

Dump Eldor
  • 92
  • 1
  • 11
1

In your situation, i would use Start-Transcript into a log file.

And then get information from the log file using filters.

su7
  • 66
  • 1
  • 7