A few Functions more

pull/278/head
KnifMelti 2023-02-03 00:48:38 +01:00
parent 29f4ef3812
commit e4bddddab5
2 changed files with 56 additions and 25 deletions

View File

@ -13,9 +13,18 @@ $Proc = @("")
#Beginning of Process Name to Wait for to End - optional wildcard (*) after, without .exe, multiple: "proc1","proc2" #Beginning of Process Name to Wait for to End - optional wildcard (*) after, without .exe, multiple: "proc1","proc2"
$Wait = @("") $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) #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"! #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" #Beginning of Desktop Link Name to Remove - optional wildcard (*) after, without .lnk, multiple: "lnk1","lnk2"
$Lnk = @("") $Lnk = @("")
@ -37,18 +46,23 @@ $AddType = ""
$DelKey = "" $DelKey = ""
$DelValue = "" $DelValue = ""
#Remove file/directory, multiple: "file1","file2" #Remove file/directory, multiple: "file1","file2" Example:
#$DelFile = @("${env:ProgramFiles}\PowerToys\PowerToys.Update.exe")
$DelFile = @("") $DelFile = @("")
#Copy file/directory #Rename file/directory. Example:
#Example: #$RenFile = "${env:ProgramFiles}\PowerToys\PowerToys.Update.exe"
#$NewName = "PowerToys.Update.org"
$RenFile = ""
$NewName = ""
#Copy file/directory. Example:
#$CopyFile = "C:\Logfiles" #$CopyFile = "C:\Logfiles"
#$CopyTo = "C:\Drawings\Logs" #$CopyTo = "C:\Drawings\Logs"
$CopyFile = "" $CopyFile = ""
$CopyTo = "" $CopyTo = ""
#Find/Replace text in file #Find/Replace text in file. Example:
#Example:
#$File = "C:\dummy.txt" #$File = "C:\dummy.txt"
#$FindText = 'brown fox' #$FindText = 'brown fox'
#$ReplaceText = 'white fox' #$ReplaceText = 'white fox'
@ -59,10 +73,6 @@ $ReplaceText = ''
#Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2" #Grant "Modify" for directory/file to "Authenticated Users" - multiple: "dir1","dir2"
$GrantPath = @("") $GrantPath = @("")
#Install App from Winget Repo, multiple: "appID1","appID2". Example:
#$AppID = @("Microsoft.PowerToys")
$AppID = @("")
#App to Run (as current logged-on user) #App to Run (as current logged-on user)
$RunUser = "" $RunUser = ""
$User = $True $User = $True
@ -80,8 +90,14 @@ if ($Proc) {
if ($Wait) { if ($Wait) {
Wait-ModsProc $Wait Wait-ModsProc $Wait
} }
if ($App) { if ($WingetIDInst) {
Uninstall-ModsApp $App Install-WingetID $WingetIDInst
}
if ($WingetIDUninst) {
Uninstall-WingetID $WingetIDUninst
}
if ($AppUninst) {
Uninstall-ModsApp $AppUninst
} }
if ($Lnk) { if ($Lnk) {
Remove-ModsLnk $Lnk Remove-ModsLnk $Lnk
@ -95,6 +111,9 @@ if ($DelKey) {
if ($DelFile) { if ($DelFile) {
Remove-ModsFile $DelFile Remove-ModsFile $DelFile
} }
if ($RenFile -and $NewName) {
Rename-ModsFile $RenFile $NewName
}
if ($CopyFile -and $CopyTo) { if ($CopyFile -and $CopyTo) {
Copy-ModsFile $CopyFile $CopyTo Copy-ModsFile $CopyFile $CopyTo
} }
@ -104,9 +123,6 @@ if ($File -and $FindText -and $ReplaceText) {
if ($GrantPath) { if ($GrantPath) {
Grant-ModsPath $GrantPath Grant-ModsPath $GrantPath
} }
if ($AppID) {
Install-ModsApp $AppID
}
if ($RunUser) { if ($RunUser) {
Invoke-ModsApp $RunUser "" "" $User Invoke-ModsApp $RunUser "" "" $User
} }

View File

@ -35,8 +35,24 @@ function Wait-ModsProc ($Wait) {
Return Return
} }
function Uninstall-ModsApp ($App) { function Install-WingetID ($WingetIDInst) {
foreach ($app in $App) 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" $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($obj in $InstalledSoftware){ foreach ($obj in $InstalledSoftware){
@ -196,6 +212,13 @@ function Remove-ModsFile ($DelFile) {
Return 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) { function Copy-ModsFile ($CopyFile, $CopyTo) {
if (Test-Path "$CopyFile") { if (Test-Path "$CopyFile") {
Copy-Item -Path $CopyFile -Destination $CopyTo -Recurse -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path $CopyFile -Destination $CopyTo -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
@ -229,11 +252,3 @@ function Grant-ModsPath ($GrantPath) {
} }
Return Return
} }
function Install-ModsApp ($AppID) {
foreach ($app in $AppID)
{
& $Winget install --id $app --accept-package-agreements --accept-source-agreements -h
}
Return
}