Any command to use in PowerShell to copy few lines from Console? - powershell

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

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...

I used $variable = command and it is working.

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

In your situation, i would use Start-Transcript into a log file.
And then get information from the log file using filters.

Related

Powershell GUI displaying text file

I have an app I developed and made a GUI for. In one of the directories I have a log.txt file.
I have a strip menu option meant to display the log file to the user. I'm wondering what would be the best method for displaying this log file?
Right now I'm just using
notepad log.txt
Which technically works but doesn't seem to be the most efficient or professional way.
I'm guessing it is probably just opening another form with a large read only text box but on the off chance someone has something that works even better I'll appreciate the suggestion.
Info displayed in log is:
Version
Description
Date

Using a script to search google

I am new to Powershell and after having a few ideas and deciding to tinker around a bit I noticed that I can write a script in Poswershell that will make a search request on a search engine that I specify.
The issue is I am not sure exactly how it works. How is this script able to know how to open my web browser when all I did was specify a string filled with an address?
I have searched up other posts and have not found anything close to what I am asking (I believe).
Here is my source and I will also add an image.
[String]$SearchFor = "bing rewards"
$Query = "http://www.bing.com/search?q=$SearchFor"
Start $Query
Thank you all for your help.
Read help on start-process
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/start-process
If you specify a non-executable file, Start-Process starts the program
that is associated with the file, similar to the Invoke-Item cmdlet.
So if I would have a TXT File in C:\test.txt and run
start-process c:\test.txt
It would open my default application assiociated with that file. On my PC it would open test.txt in notepad.
Hope that makes it clear now.
It simply uses the default application to open URLs on your desktop i.e. your default Internet browser.
Same behavior if you paste the URL (without variables) in your Start > Run box.

Powershell Help, the code i have sends a email out to people, need to save a the data of the code but not as a text file

I am new to powershell and need some help. I have a code which runs everyday and sends an email out to people regarding the server status and other details. What i need to do is save that file as maybe an output file or something so if the customer wants can go in to powershell type in the script command and it comes up with the information thats on the email
Is there a way to do this. This cant be a text file. Has to be something u can type and the data comes up?
please help, thanks in advance
Os
Without code the only definite answer I can give you is using the Out-File command. I do not see why it can't be a txt file (because it's just an email)since data can come up and be typed. You can always Out-File to excel or csv, it really all depends on what you're trying to ask.

Convert MS-Office to pdf

I'm using OfficeToPDF to convert the MS-Office files to pdf. However, I only can run the command:
OfficeToPDF test.doc test.pdf
in cmd (windows)
I want to embed this code into my cgi file (Perl). Can anyone show me how to do this, thank you!
(I used:
system("OfficeToPDF test.doc test.pdf");
but seems it's not work)
That should work but your envormental parameters might not be setup right, you should include full paths(or proper relative ones) and see if that fixes the problem up. If not you might want to post your debug log, or enable verbose output. Your perl also might not be setup to execute shell commands for security reasons when in cgi mode and the logs would help clarify that.
Try to:
use the full paths to OfficeToPDF and target PDF location because usually, the CGI scripts are run in another user context,
check, the CGI user has reading and writing rights for both files (and, off sure, right to execute the OfficeToPDF)
But it depends what means "it's not work", of sure.

perl excel to pdf

I'm using perl with an excel template to try to make creating invoices for clients somewhat automated. My only issue is that I'd really like to be able to convert this excel file to a PDF when I'm done, but I can't seem to find any perl modules that do anything of the sort. Anyone ever heard of something like this being done? I know it can be done somehow, since word and open office manage to do it!
Simply shell out to unoconv.
There are also Perl bindings to UNO, but last time I looked, they didn't work.
You may have to convert/flatten the Excel file first, and then figure out a way to pipe it in, but this may get you headed in the right direction http://metacpan.org/pod/PDF::Create