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

Arguments #52

Merged
merged 6 commits into from
Jun 30, 2022
Merged

Arguments #52

merged 6 commits into from
Jun 30, 2022

Conversation

Carterpersall
Copy link
Contributor

@Carterpersall Carterpersall commented May 20, 2022

This will be expanded for the rest of the script as the script restructure for runspaces is finished.

- Using $env:args, the script scans for arguments; then if found, Invokes the Runspace associated with said arg. Or in the case of the old panels, just opens the panel.
  - \b is to prevent mutual words from causing issues (Ex: Install and InstallUpgrade would conflict without \b)
Forgot to save before previous commit  : |
@DeveloperDurp
Copy link
Contributor

Looks like it should work though it might need to be lower in the script as the functions/scripts wouldn't be loaded into memory yet. Might even need to go until right before line 1316.

Hmm....

We might want to move everything that generates the GUI lower in the script as well. That way the functions/scripts load first and if we want CLI only it doesn't have to spend time loading things it doesn't need.

@DeveloperDurp
Copy link
Contributor

Well that's interesting lol, ran it twice. But I had to put it at the bottom of the script.

image

(Code at top)
image

- The arg check occurred too early, causing an error
@Carterpersall
Copy link
Contributor Author

The positioning issue should be fixed

@DeveloperDurp
Copy link
Contributor

Quick test of the quit after I think we will need to add some logic so it can wait for the runspaces to finish. Or we might be able to do an invoke-command -scriptblock $InstallUpgrade since we don't have to worry about a gui

I will see what's going on with the double running of the install upgrade. Might need to rework the runspaces a little.

@Carterpersall
Copy link
Contributor Author

Doing that seems to work
For me though it ran a few more than 2 times:
image

- Replaced Invoke-Runspace with Invoke-Command as there is no need to worry about the gui when running unattended
@DeveloperDurp
Copy link
Contributor

Perfect! I will work on the runspaces with the CLI in mind

@Carterpersall
Copy link
Contributor Author

Doing that seems to work For me though it ran a few more than 2 times: image

I can't seem to recreate this issue so I dunno what's causing it to happen only occasionally

@DeveloperDurp
Copy link
Contributor

Perhaps lingering runspaces from the last run, it works perfectly on my win10 instance.

@Carterpersall
Copy link
Contributor Author

Perhaps lingering runspaces from the last run, it works perfectly on my win10 instance.

Oh yeah, that would make sense as that was my first time trying the different method.

@Carterpersall
Copy link
Contributor Author

Carterpersall commented May 20, 2022

I might want to make another arg that if it's passed, none of the message boxes show. Currently, the message boxes pause the script making it not unattended. Another way to do it would be to have a check every time a message box is shown that checks if the argument is passed, then doesn't show the box when if it is passed.
Though this would mean that if QuitAfter isn't passed and the corresponding button is pressed, no message boxes would show. This could be prevented though by setting $env:args to an empty string before the form is opened and after the argument check.

But for now, I'm going to bed as all this programming has fried my brain.

@DeveloperDurp
Copy link
Contributor

Yeah, that's something I am going to work on. I might have to separate the scripts a little and have a gui portion that controls the gui and formats the data into the same arguments you would use with say winget. That way you could pass $arg = "install:git.git" and it will install it the same way.

Also going to play around with the error handling to have it output errors to the terminal window and also allow you the option to do verbose in case you want to see what the script is doing.

@DeveloperDurp
Copy link
Contributor

@Carterpersall FYI, the new script to call is $sync.ScriptsInstallPrograms, separated the GUI portion from the install script to make it easier to get the CLI functions to work without spamming message boxes.

@DeveloperDurp
Copy link
Contributor

Once #50 gets merged you can add Installs to your arguments. Though we would need to add some logic so you could add in programs

Something like

$env:args = "UndoTweaks QuitAfter Install:git.git,winscp.winscp"

If($env:args -match '\bInstall\b'){
    Write-Verbose "Running"
    $Programstoinstall = (($env:args-split " " | Where-Object {$_ -like "install*"} ) -split ":")[1]
    Invoke-Command -scriptblock  $sync.ScriptsInstallPrograms -ArgumentList $Programstoinstall
}

We can also add this to get output in the console window
If($env:args -match '\bVerbose\b'){$VerbosePreference = "Continue"}

@Carterpersall
Copy link
Contributor Author

Great Idea! When I find the time, I'll implement it.

 - Added arg check for Install
   - Format is 'Install: company.program,.company.program2'
@Carterpersall
Copy link
Contributor Author

Added it in the most recent commit

@DeveloperDurp
Copy link
Contributor

$sync.ScriptsInstallUpgrade will also be available in the same MR

@ChrisTitusTech ChrisTitusTech merged commit 55616db into ChrisTitusTech:test Jun 30, 2022
@Carterpersall Carterpersall deleted the Arguments branch July 21, 2022 11:49
ChrisTitusTech added a commit that referenced this pull request Sep 5, 2022
* xml decouple

* Typos: Documents, Start installs (#18)

Document -> Documents
Start install -> Start installs

Co-authored-by: Chris Titus <[email protected]>

* Added DISM command and button to tool (#19)

* Added DISM command and button to tool

* Added additional scans and colours to make it clear when each scan type starts

Co-authored-by: Chris Titus <[email protected]>

* Fix issue in #14 (#20)

* Fix issue in #14

 - It seems that Chris forgot to add a button for the Repair Windows Update Script and accidentally put it under the Default Windows Update Settings button.
   - Fixed by adding the $WPFFixesUpdate.Add_Click function before the Reset Script
   - Fixes #14

* decoupling xaml and ps1 (#7)

Co-authored-by: Chris Titus <[email protected]>

Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: Chris Titus <[email protected]>

* Add winget check and installer (#21)

* Add winget check and installer

 - Adds Check if winget is installed
   - If not installed, checks if the computer is running 1809+ and if the computer is running Windows Server or LTSC
    - If running pre-1809, winget install stops as it is not supported
    - If running Windows Server or Windows LTSC, runs alternative installer compatible with those editions of Windows

* decoupling xaml and ps1 (#7)

Co-authored-by: Chris Titus <[email protected]>

Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: Chris Titus <[email protected]>

* Small Fixes. (#22)

* Update winutil.ps1

* Use Curl instead of Bits transfer for O&O Shutup.

* Update winutil.ps1

* decoupling xaml and ps1 (#7)

Co-authored-by: Chris Titus <[email protected]>

Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: Chris Titus <[email protected]>

* upload example (#12)

Co-authored-by: Chris Titus <[email protected]>

* code format using powershell VS code extension (#28)

* Working runspaces (#32)

* upload example

* decoupling xaml and ps1 (#7)

Co-authored-by: Chris Titus <[email protected]>

* Update README.md

* convert to runspaces

* add security updates to invoke-button

* Update README.md

removed extra text about test branch

* initial commit to test restmethod

* formatting

Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: Chris Titus <[email protected]>

* Fix bug in #39 (#40)

- Closes #39
  - $arch is not set to a value in the script, and it throws an error when the If-Statement is called
    - Fixed by replacing the $arch variable check with a wmic check

* Fix and Tweak #19 (#43)

* Fix Issue in #19

 - Pull Request #19 didn't add an entry for PanelDISM into MainWindow.xaml, causing an error to be thrown when the script if executed and a button to not be created
   - Fixed by adding an entry into MainWIndow.xaml that creates the needed button under the FixesUpdate button
   - Note: To see the fix, you need to comment line 9 and uncomment line 8 to use the local MainWindow.xaml instead of the one in the Main Branch

* Fix Formatting and Tweak Things

 - Fixed the formatting
 - Tweaked Write-Host's
   - Added newlines (`n) to space out the Statuses
   - Added progress indicators
     - Required "s and 's to be swapped so x/4 does not perform an operation

* Slight Tweak

* Added Uncheck all button in the Install tab (#29)

* Revert "Added Uncheck all button in the Install tab (#29)" (#72)

This reverts commit 8338371.

* Throw warning if no programs are selected for installation (#30)

Co-authored-by: Chris Titus <[email protected]>

* Fix a few spelling errors (#44)

- Fixed a few spelling errors
   - dependancies -> dependencies
   - Evnronment -> Environment
   - haved -> have
   - Hibernte -> Hibernate
   - histroy -> history
   - extentions -> extensions

* Arguments (#52)

* Implement Arguments

- Using $env:args, the script scans for arguments; then if found, Invokes the Runspace associated with said arg. Or in the case of the old panels, just opens the panel.
  - \b is to prevent mutual words from causing issues (Ex: Install and InstallUpgrade would conflict without \b)

* Actually add \b

Forgot to save before previous commit  : |

* Fix Order Issue

- The arg check occurred too early, causing an error

* Remove Invoke-Runspace

- Replaced Invoke-Runspace with Invoke-Command as there is no need to worry about the gui when running unattended

* Add Program Install Arg Check

 - Added arg check for Install
   - Format is 'Install: company.program,.company.program2'

Co-authored-by: Chris Titus <[email protected]>

* Replace all instances of "incase" to "in case" (#60)

Co-authored-by: Chris Titus <[email protected]>

* Added  -NoRestart to WindowsOptionalFeature (#65)

* Handled UAC exit on install and upgrade (#31)

Co-authored-by: ChrisTitusTech <[email protected]>
Co-authored-by: Ayoub Hebbaj <[email protected]>
Co-authored-by: Jards <[email protected]>
Co-authored-by: Carter <[email protected]>
Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: Aetopia <[email protected]>
Co-authored-by: DeveloperDurp <[email protected]>
Co-authored-by: Rahul Somasundaram <[email protected]>
Co-authored-by: GrahamboJangles <[email protected]>
Co-authored-by: PWall <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants