Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 2e5d241

Browse files
authored
Merge pull request #79 from KnifMelti/main
A few Functions more
2 parents f250363 + 5e1bdf9 commit 2e5d241

File tree

2 files changed

+56
-11
lines changed

2 files changed

+56
-11
lines changed

mods/_AppID-template.ps1

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ $Proc = @("")
1313
#Beginning of Process Name to Wait for to End - optional wildcard (*) after, without .exe, multiple: "proc1","proc2"
1414
$Wait = @("")
1515

16+
#Install App from Winget Repo, multiple: "appID1","appID2". Example:
17+
#$WingetIDInst = @("Microsoft.PowerToys")
18+
$WingetIDInst = @("")
19+
20+
#WingetID to uninstall in default manifest mode (silent if supported)
21+
#Multiple: "ID1","ID2". Example:
22+
#$WingetIDUninst = @("Microsoft.PowerToys")
23+
$WingetIDUninst = @("")
24+
1625
#Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry)
1726
#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"!
18-
$App = @("")
27+
$AppUninst = @("")
1928

2029
#Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
2130
$Lnk = @("")
@@ -37,18 +46,23 @@ $AddType = ""
3746
$DelKey = ""
3847
$DelValue = ""
3948

40-
#Remove file/directory, multiple: "file1","file2"
49+
#Remove file/directory, multiple: "file1","file2" Example:
50+
#$DelFile = @("${env:ProgramFiles}\PowerToys\PowerToys.Update.exe")
4151
$DelFile = @("")
4252

43-
#Copy file/directory
44-
#Example:
53+
#Rename file/directory. Example:
54+
#$RenFile = "${env:ProgramFiles}\PowerToys\PowerToys.Update.exe"
55+
#$NewName = "PowerToys.Update.org"
56+
$RenFile = ""
57+
$NewName = ""
58+
59+
#Copy file/directory. Example:
4560
#$CopyFile = "C:\Logfiles"
4661
#$CopyTo = "C:\Drawings\Logs"
4762
$CopyFile = ""
4863
$CopyTo = ""
4964

50-
#Find/Replace text in file
51-
#Example:
65+
#Find/Replace text in file. Example:
5266
#$File = "C:\dummy.txt"
5367
#$FindText = 'brown fox'
5468
#$ReplaceText = 'white fox'
@@ -76,8 +90,14 @@ if ($Proc) {
7690
if ($Wait) {
7791
Wait-ModsProc $Wait
7892
}
79-
if ($App) {
80-
Uninstall-ModsApp $App
93+
if ($WingetIDInst) {
94+
Install-WingetID $WingetIDInst
95+
}
96+
if ($WingetIDUninst) {
97+
Uninstall-WingetID $WingetIDUninst
98+
}
99+
if ($AppUninst) {
100+
Uninstall-ModsApp $AppUninst
81101
}
82102
if ($Lnk) {
83103
Remove-ModsLnk $Lnk
@@ -91,6 +111,9 @@ if ($DelKey) {
91111
if ($DelFile) {
92112
Remove-ModsFile $DelFile
93113
}
114+
if ($RenFile -and $NewName) {
115+
Rename-ModsFile $RenFile $NewName
116+
}
94117
if ($CopyFile -and $CopyTo) {
95118
Copy-ModsFile $CopyFile $CopyTo
96119
}

mods/_Mods-Functions.ps1

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,24 @@ function Wait-ModsProc ($Wait) {
3535
Return
3636
}
3737

38-
function Uninstall-ModsApp ($App) {
39-
foreach ($app in $App)
38+
function Install-WingetID ($WingetIDInst) {
39+
foreach ($app in $WingetIDInst)
40+
{
41+
& $Winget install --id $app --accept-package-agreements --accept-source-agreements -h
42+
}
43+
Return
44+
}
45+
46+
function Uninstall-WingetID ($WingetIDUninst) {
47+
foreach ($app in $WingetIDUninst)
48+
{
49+
& $Winget uninstall --id $app -e --accept-source-agreements -h
50+
}
51+
Return
52+
}
53+
54+
function Uninstall-ModsApp ($AppUninst) {
55+
foreach ($app in $AppUninst)
4056
{
4157
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
4258
foreach ($obj in $InstalledSoftware){
@@ -152,7 +168,6 @@ function Uninstall-ModsApp ($App) {
152168
}
153169
Return
154170
}
155-
156171
function Remove-ModsLnk ($Lnk) {
157172
foreach ($link in $Lnk)
158173
{
@@ -197,6 +212,13 @@ function Remove-ModsFile ($DelFile) {
197212
Return
198213
}
199214

215+
function Rename-ModsFile ($RenFile, $NewName) {
216+
if (Test-Path "$RenFile") {
217+
Rename-Item -Path $RenFile -NewName $NewName -Force -ErrorAction SilentlyContinue | Out-Null
218+
}
219+
Return
220+
}
221+
200222
function Copy-ModsFile ($CopyFile, $CopyTo) {
201223
if (Test-Path "$CopyFile") {
202224
Copy-Item -Path $CopyFile -Destination $CopyTo -Recurse -Force -ErrorAction SilentlyContinue | Out-Null

0 commit comments

Comments
 (0)