Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Arguments and Unattended Running #51

Closed
Carterpersall opened this issue May 19, 2022 · 12 comments
Closed

Feature Request: Arguments and Unattended Running #51

Carterpersall opened this issue May 19, 2022 · 12 comments

Comments

@Carterpersall
Copy link
Contributor

Is your feature request related to a problem? Please describe.
It would be very useful if the script had the ability to run unattended and silent. This would be useful for people who know what they want to run and want to run a command and wait for it to finish. It would also be helpful for people like IT's and System Admins to use if they wanted to deploy the script during the setup of a network of computers.

Describe the solution you'd like
The solution would be much like what I implemented in ChrisTitusTech/win10script#331 where you pass arguments into the script and the script runs them and then exits (if the accompanying arg is set). It will be much more difficult to implement in the new variant of the script though.
I will attempt to implement it in a pull request when the current restructuring of the script for runspaces is complete as I don't want to interfere with that.

Additional context
I'm putting this here for others to refer to and offer suggestions and to prevent someone else from opening an issue on it while I'm working on it.

@Carterpersall Carterpersall changed the title Feature Request: Argments and Unattended Running Feature Request: Arguments and Unattended Running May 19, 2022
@DeveloperDurp
Copy link
Contributor

That's a good idea and shouldn't be hard to implement, though I am not sure how easy it would be to pass arguments through invoke-webrequest.

At that point I would suggest removing the gui from the main script and creating a "launcher" script that if you say "command -nogui -install apps git,firefox,..." it could run the same script the gui does (at least with how I have been trying to implement the runspaces).

@Carterpersall
Copy link
Contributor Author

Carterpersall commented May 19, 2022

After a few hours of throwing ideas at Windows Terminal, I got something that might work. Working off of the example given at https://www.codementor.io/@slavko/creating-parametrized-powershell-one-liners-rx1vk1nyc I got this using the script in my pull request:

$overrideParams = @{Dark = '$true'}; Invoke-Command -ScriptBlock ([scriptblock]::create(".{$((New-Object net.webclient).DownloadString('https://github.com/Carterpersall/win10script/raw/Arguments/win10debloat.ps1'))} $(&{$args} @overrideParams)"))

What the code snippet does is sets the arguments to the $overrideParams variable (separate args with ;), and run the script with arguments using Invoke-Command by downloading the script and running the path using the arguments. At least that's how I think it works. Theres still a few parts of it that still look like it uses black magic though.
With some work shortening it down and simplifying it, it could work.

@DeveloperDurp
Copy link
Contributor

DeveloperDurp commented May 19, 2022

That looks fairly straight forward, definitely not super easy to remember/ type in real quick. Would work in a script scenario though. I will do some research as well. I did test passing the dev environment variable in one line and it seemed to work.

Might be possible to do something like this.

$env:args = "nogui;install,git,firefox,..." ; iwr -useb https://christitus.com/win | iex

Then have the initial script detect if that $env:args variable is set and if it is run based off that.

@Carterpersall
Copy link
Contributor Author

Yeah that might be a better solution then the black magic I gave.

The next issue will be calling the needed parts of the script based off of the arguments passed. What I did previously is split the .add_click code blocks into separate functions, then call the functions in both the argument and the accompanying .add_click code block

@DeveloperDurp
Copy link
Contributor

Gotcha, I believe with the way I work with runspaces it shouldn't be hard to convert it to be a CLI tool as well. The way that I am doing is I make all the .add_click blocks the same and have it send the name of the button to an invoke-button function so I can control the action that way. From there and depending on the button I run another function called invoke-runspace and pass a script block variable that's defined as a variable. As long as the arguments provided in the CLI are the same as the ones provided as the GUI we can use the same script blocks and get the same results.

@Carterpersall
Copy link
Contributor Author

Carterpersall commented May 20, 2022

Yeah, theoretically that should work.
If I end up having the time (and motivation), I'll put together a pull request on a proof of concept.

@Carterpersall Carterpersall mentioned this issue May 20, 2022
@Carterpersall
Copy link
Contributor Author

Carterpersall commented May 20, 2022

I created a proof of concept in pull request #52.

When the script restructure is finished, I can expand the argument list to add the other Codeblocks

@DeveloperDurp
Copy link
Contributor

Technically this feature has been added to the runspace version lol, don't know if we want to back port it to the current codebase

@0nelight 0nelight mentioned this issue Nov 19, 2022
@0nelight
Copy link

0nelight commented Nov 19, 2022

I created a python script to automate winutil. It can be helpful for automating until someone has the time and the competence to implement command line parameters.

gist.github.com

@YoraiLevi
Copy link
Contributor

Has there been no progress on a cli version as of yet?

@DeveloperDurp
Copy link
Contributor

I have not had a chance yet to port over the CLI functions from the old runspace.ps1 script.

@YoraiLevi
Copy link
Contributor

If someone needs some basic implementations for cli; beware that tweaks that use winget may require interaction as in the gui.

Invoke-WebRequest https://raw.githubusercontent.com/YoraiLevi/winutil_tweaks_cli/master/winutil_cli.ps1 -OutFile winutil_cli.ps1
winutil_cli.ps1 -TweakNames WPFBingSearch,WPFEssTweaksAH,WPFEssTweaksDeBloat,WPFEssTweaksDeleteTempFiles,WPFEssTweaksDiskCleanup,WPFEssTweaksDVR,WPFEssTweaksHiber,WPFEssTweaksHome,WPFEssTweaksLoc,WPFEssTweaksOO,WPFEssTweaksRemoveEdge,WPFEssTweaksRemoveOnedrive,WPFEssTweaksServices,WPFEssTweaksStorage,WPFEssTweaksTele,WPFEssTweaksWifi,WPFMiscTweaksDisableipsix,WPFMiscTweaksDisableMouseAcceleration,WPFMiscTweaksDisableNotifications,WPFMiscTweaksDisableUAC,WPFMiscTweaksDisplay,WPFMiscTweaksEnableipsix,WPFMiscTweaksEnableMouseAcceleration,WPFMiscTweaksEnableVerboselogon,WPFMiscTweaksExt,WPFMiscTweaksLapNum,WPFMiscTweaksNum,WPFMiscTweaksRightClickMenu,WPFMiscTweaksUTC -WindowsFeaturesBundles WPFFeaturenfs,WPFFeaturesdotnet,WPFFeatureshyperv,WPFFeatureslegacymedia,WPFFeaturewsl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants