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.
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Reddrgn2
Posts: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: 49
Last visit: Wed Nov 08, 2023 10:34 am
Answers: 1

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
Last visit: Sun Jul 11, 2021 7:29 pm

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.
This topic is 3 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked