Adding Switch function

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
Reddrgn2
Posts: 40
Joined: Wed May 23, 2018 6:13 am

Adding Switch function

Post by Reddrgn2 »

I am trying to see if what I am thinking in my head was possible, close to way it is in my head.

Goal: add a function/switch to script(any) that will allow export after displaying results.

Example: run "Get-MsolUser -All -UnlicensedUsersOnly" it displays results. Then to export it I would need to add export "Get-MsolUser -All -UnlicensedUsersOnly | export-csv ***"

Idea: run "Get-MsolUser -All -UnlicensedUsersOnly" then have something added to to display results, then ask/prompt if want to export - if yes then it uses the already pre-planed export ($export = Export-csv ****). If select no, then it ends the script (allowing other scripts to run). Thought of pausing but reviewing results might take a little longer then allotted 30seconds.

Anyone have thoughts or ideas? Anyone do anything like this or see possible issues?

jvierra
Posts: 14691
Joined: Tue May 22, 2007 9:57 am
Answers: 7
Has voted: 2 times
Been upvoted: 5 times

Re: Adding Switch function

Post by jvierra »

There are no functions or switches that will do what you ask. See the examples for the following command.
help Read-Host -online
I suggest starting with this book (free) to get a basic understanding of PowerShell and scripting. It will help you understand how to ask your question.

https://www.sapien.com/books_training/W ... werShell-4

User avatar
Reddrgn2
Posts: 40
Joined: Wed May 23, 2018 6:13 am

Re: Adding Switch function

Post by Reddrgn2 »

I have read it but I also know there are ways around certain things or ways to get things to work the way wanted. Also know somethings are not do able. Can't always know the limits unless you ask

User avatar
robrtitus
Posts: 4
Joined: Mon Dec 16, 2013 9:39 am

Re: Adding Switch function

Post by robrtitus »

Not a switch but the out-gridview cmdlet is commonly used for this case. You could write something like this:

Code: Select all

get-process | out-gridview -PassThru | Export-Csv c:\temp\someprocesses.csv
The gridview is in and out of support though, based on the PowerShell version and host you're using. You'll need to be sure you can use it in your target deployment before relying on it.

Locked