1) I am trying to export the output of the script below to csv. 2) I want to bypass the execution policy.
My goal is have the person run the script or executable (.ps1 converted to .exe) and have it grab the information and export the data to their root (c:\) drive.
I've tried looking at other scripts where the export-csv works, but can't seem to nail down the positioning.
Many thanks in advance
As far as I know, "export" is not an alias to "export-csv".
Also, have you checked if the user has permission to create a file to C:\?
I corrected "export" to "export-csv" and then ran the script. It exports a CSV file, however the file does not contain the data that is output to the screen. I've checked and the user has the rights to export to C:\
I've not tried running your script but at a glance it looks like the problem is that you're exporting the CSV in the BEGIN block.
The BEGIN block will execute the first time the function is called in the pipeline and that's the only time it will execute.
You'll need to move the Export-CSV to the PROCESS block but beware that with your current code you'll still get unexpected results because you'll be overwriting the CSV each time the process block runs. i.e. you'll end up with just the data from the last computer you process.
I really appreciate your feedback. I will definitely keep a mental note of your suggestions. I was in a hurry and decided to use a batch file to get the necessary results. I will just my script and test based on your comments. Subsequently I will reply with my results. I think it should be unnecessary for me to use the batch file anyway.
You must be logged in to reply to this topic.