Skip to content

Commit

Permalink
Merge pull request Romanitho#79 from KnifMelti/main
Browse files Browse the repository at this point in the history
A few Functions more
  • Loading branch information
Romanitho authored Feb 14, 2023
2 parents f250363 + 5e1bdf9 commit 2e5d241
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 11 deletions.
39 changes: 31 additions & 8 deletions mods/_AppID-template.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ $Proc = @("")
#Beginning of Process Name to Wait for to End - optional wildcard (*) after, without .exe, multiple: "proc1","proc2"
$Wait = @("")

#Install App from Winget Repo, multiple: "appID1","appID2". Example:
#$WingetIDInst = @("Microsoft.PowerToys")
$WingetIDInst = @("")

#WingetID to uninstall in default manifest mode (silent if supported)
#Multiple: "ID1","ID2". Example:
#$WingetIDUninst = @("Microsoft.PowerToys")
$WingetIDUninst = @("")

#Beginning of App Name string to Silently Uninstall (MSI/NSIS/INNO/EXE with defined silent uninstall in registry)
#Multiple: "app1*","app2*", required wildcard (*) after; search is done with "-like"!
$App = @("")
$AppUninst = @("")

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

#Remove file/directory, multiple: "file1","file2"
#Remove file/directory, multiple: "file1","file2" Example:
#$DelFile = @("${env:ProgramFiles}\PowerToys\PowerToys.Update.exe")
$DelFile = @("")

#Copy file/directory
#Example:
#Rename file/directory. Example:
#$RenFile = "${env:ProgramFiles}\PowerToys\PowerToys.Update.exe"
#$NewName = "PowerToys.Update.org"
$RenFile = ""
$NewName = ""

#Copy file/directory. Example:
#$CopyFile = "C:\Logfiles"
#$CopyTo = "C:\Drawings\Logs"
$CopyFile = ""
$CopyTo = ""

#Find/Replace text in file
#Example:
#Find/Replace text in file. Example:
#$File = "C:\dummy.txt"
#$FindText = 'brown fox'
#$ReplaceText = 'white fox'
Expand Down Expand Up @@ -76,8 +90,14 @@ if ($Proc) {
if ($Wait) {
Wait-ModsProc $Wait
}
if ($App) {
Uninstall-ModsApp $App
if ($WingetIDInst) {
Install-WingetID $WingetIDInst
}
if ($WingetIDUninst) {
Uninstall-WingetID $WingetIDUninst
}
if ($AppUninst) {
Uninstall-ModsApp $AppUninst
}
if ($Lnk) {
Remove-ModsLnk $Lnk
Expand All @@ -91,6 +111,9 @@ if ($DelKey) {
if ($DelFile) {
Remove-ModsFile $DelFile
}
if ($RenFile -and $NewName) {
Rename-ModsFile $RenFile $NewName
}
if ($CopyFile -and $CopyTo) {
Copy-ModsFile $CopyFile $CopyTo
}
Expand Down
28 changes: 25 additions & 3 deletions mods/_Mods-Functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,24 @@ function Wait-ModsProc ($Wait) {
Return
}

function Uninstall-ModsApp ($App) {
foreach ($app in $App)
function Install-WingetID ($WingetIDInst) {
foreach ($app in $WingetIDInst)
{
& $Winget install --id $app --accept-package-agreements --accept-source-agreements -h
}
Return
}

function Uninstall-WingetID ($WingetIDUninst) {
foreach ($app in $WingetIDUninst)
{
& $Winget uninstall --id $app -e --accept-source-agreements -h
}
Return
}

function Uninstall-ModsApp ($AppUninst) {
foreach ($app in $AppUninst)
{
$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware){
Expand Down Expand Up @@ -152,7 +168,6 @@ function Uninstall-ModsApp ($App) {
}
Return
}

function Remove-ModsLnk ($Lnk) {
foreach ($link in $Lnk)
{
Expand Down Expand Up @@ -197,6 +212,13 @@ function Remove-ModsFile ($DelFile) {
Return
}

function Rename-ModsFile ($RenFile, $NewName) {
if (Test-Path "$RenFile") {
Rename-Item -Path $RenFile -NewName $NewName -Force -ErrorAction SilentlyContinue | Out-Null
}
Return
}

function Copy-ModsFile ($CopyFile, $CopyTo) {
if (Test-Path "$CopyFile") {
Copy-Item -Path $CopyFile -Destination $CopyTo -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
Expand Down

0 comments on commit 2e5d241

Please sign in to comment.