Skip to content

Commit

Permalink
Arguments (#52)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Carterpersall and ChrisTitusTech authored Jun 30, 2022
1 parent dd65f70 commit 55616db
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion winutil-test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
$inputXML = (new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/ChrisTitusTech/winutil/main/MainWindow.xaml")
$global:sync["applications"] = Invoke-RestMethod "https://raw.githubusercontent.com/ChrisTitusTech/winutil/test/applications.json"
}

$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[xml]$XAML = $inputXML
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
Expand Down Expand Up @@ -1298,4 +1298,27 @@ $xaml.SelectNodes("//*[@Name]") | ForEach-Object {$global:sync["$("$($_.Name)")"

#endregion scripts

# Arguments
If($env:args){
Write-Verbose "Arguments Detected, Running Args"
If($env:args -match '\bInstallUpgrade\b'){Invoke-Command -scriptblock $InstallUpgrade}
If($env:args -match '\bUndoTweaks\b'){Invoke-Command -scriptblock $undotweaks}
If($env:args -match '\bPanelControl\b'){cmd /c control}
If($env:args -match '\bPanelNetwork\b'){cmd /c ncpa.cpl}
If($env:args -match '\bPanelPower\b'){cmd /c powercfg.cpl}
If($env:args -match '\bPanelSound\b'){cmd /c mmsys.cpl}
If($env:args -match '\bPanelSystem\b'){cmd /c sysdm.cpl}
If($env:args -match '\bPanelUser\b'){cmd /c "control userpasswords2"}
If($env:args -match '\bDefaultUpdates\b'){Invoke-Command -scriptblock $Updatesdefault}
If($env:args -match '\bDisableUpdates\b'){Invoke-Command -scriptblock $Updatesdisable}
If($env:args -match '\bEnableSecurity\b'){Invoke-Command -scriptblock $Updatessecurity}
If($env:args -match '\bQuitAfter\b'){Break}
If($env:args -match '\bInstall\b'){
$ProgramstoInstall = (($env:args-split " " | Where-Object {$_ -like "install*"} ) -split ":")[1]
Write-Verbose "Installing $ProgramstoInstall."
Invoke-Command -scriptblock $sync.ScriptsInstallPrograms -ArgumentList $ProgramstoInstall
}
}

# Create Form
$global:sync["Form"].ShowDialog() | out-null

0 comments on commit 55616db

Please sign in to comment.