Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wingetScripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
icommonsCRC
wingetScripts
Commits
34e1f086
Commit
34e1f086
authored
7 months ago
by
icommonsCRC
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
226bb34f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wingetInstaller.ps1
+173
-0
173 additions, 0 deletions
wingetInstaller.ps1
with
173 additions
and
0 deletions
wingetInstaller.ps1
0 → 100644
+
173
−
0
View file @
34e1f086
# Self-elevate the script if required
if
(
-Not
([
Security.Principal.WindowsPrincipal
]
[
Security.Principal.WindowsIdentity
]::
GetCurrent
())
.
IsInRole
([
Security.Principal.WindowsBuiltInRole
]
'Administrator'
))
{
if
([
int
](
Get-CimInstance
-Class
Win32_OperatingSystem
|
Select-Object
-ExpandProperty
BuildNumber
)
-ge
6000
)
{
# PowerShell 5 and later
$CommandLine
=
"-File
`"
"
+
$MyInvocation
.
MyCommand
.
Path
+
"
`"
"
+
$MyInvocation
.
UnboundArguments
Start-Process
-FilePath
PowerShell.exe
-Verb
Runas
-ArgumentList
$CommandLine
Exit
}
}
# List of applications to install
$applications
=
@(
# Applications available via PatchMyPC
"dotPDN.PaintDotNet"
,
"notepad++.notepad++"
,
"PuTTY.PuTTY"
,
"Posit.RStudio"
,
"Microsoft.VisualStudioCode"
,
"VideoLAN.VLC"
,
"Mozilla.Firefox"
,
"WiresharkFoundation.Wireshark"
,
"WinSCP.WinSCP"
,
"7zip.7zip"
,
"HandBrake.HandBrake"
,
"OBSProject.OBSStudio"
,
# Applications to install manually or with winget
"Zoom.Zoom"
,
"JetBrains.IntelliJIDEA.Community"
,
"AivarAnnamaa.Thonny"
,
"Insecure.Nmap"
,
"JetBrains.PyCharm.Community"
,
"Racket.Racket"
)
# Initialize status tracking hashtables
$installationStatus
=
@{}
$updateStatus
=
@{}
$errorMessages
=
@{}
# Function to check if an application is installed
function
Test-ApplicationInstalled
{
param
(
[
string
]
$AppId
)
$listResult
=
winget
list
--id
$AppId
--accept-source-agreements
2
>
&
1
return
$listResult
-like
"*
$AppId
*"
}
# Function to check if an application has updates available
function
Test-UpdateAvailable
{
param
(
[
string
]
$AppId
)
$upgradeResult
=
winget
upgrade
--id
$AppId
2
>
&
1
return
$upgradeResult
-notlike
"*No applicable upgrade found.*"
}
# Add a start message
Write-Host
"Starting installation/update process..."
-ForegroundColor
Green
Write-Host
"This script will install or update the following applications:"
-ForegroundColor
Yellow
$applications
|
ForEach-Object
{
Write-Host
" -
$_
"
-ForegroundColor
Cyan
}
Write-Host
""
# Counter for tracking progress
$totalApps
=
$applications
.
Count
$currentApp
=
0
# Iterate through the applications and install or update each
foreach
(
$app
in
$applications
)
{
$currentApp
++
Write-Host
"
`n
Processing (
$currentApp
/
$totalApps
):
$app
..."
-ForegroundColor
Yellow
try
{
# Check if the application is already installed
$wasInstalled
=
Test-ApplicationInstalled
-AppId
$app
if
(
$wasInstalled
)
{
Write-Host
"
$app
is already installed. Checking for updates..."
-ForegroundColor
Cyan
# Check if updates are available
if
(
Test-UpdateAvailable
-AppId
$app
)
{
Write-Host
"Update available for
$app
. Updating..."
-ForegroundColor
Green
winget
upgrade
--id
$app
--silent
--accept-package-agreements
--accept-source-agreements
# Verify update
if
(
-not
(
Test-UpdateAvailable
-AppId
$app
))
{
$updateStatus
[
$app
]
=
"Success"
Write-Host
"
$app
updated successfully!"
-ForegroundColor
Green
}
else
{
$updateStatus
[
$app
]
=
"Failed"
Write-Host
"Update may have failed for
$app
"
-ForegroundColor
Yellow
}
}
else
{
$updateStatus
[
$app
]
=
"UpToDate"
Write-Host
"
$app
is up to date."
-ForegroundColor
Cyan
}
}
else
{
Write-Host
"
$app
is not installed. Installing..."
-ForegroundColor
Green
winget
install
--id
$app
--silent
--accept-package-agreements
--accept-source-agreements
# Verify installation
if
(
Test-ApplicationInstalled
-AppId
$app
)
{
$installationStatus
[
$app
]
=
"Success"
Write-Host
"
$app
installed successfully!"
-ForegroundColor
Green
}
else
{
$installationStatus
[
$app
]
=
"Failed"
Write-Host
"Installation may have failed for
$app
"
-ForegroundColor
Red
}
}
}
catch
{
$errorMessages
[
$app
]
=
$_
.
Exception
.
Message
Write-Host
"Failed to process
$app
. Error:
$_
"
-ForegroundColor
Red
}
}
# Generate and display summary
Write-Host
"
`n
==============================="
-ForegroundColor
Yellow
Write-Host
"Installation/Update Summary"
-ForegroundColor
Yellow
Write-Host
"==============================="
-ForegroundColor
Yellow
# Show successful installations
$successfulInstalls
=
$installationStatus
.
GetEnumerator
()
|
Where-Object
{
$_
.
Value
-eq
"Success"
}
if
(
$successfulInstalls
)
{
Write-Host
"
`n
Successfully Installed:"
-ForegroundColor
Green
$successfulInstalls
|
ForEach-Object
{
Write-Host
" -
$(
$_
.
Key
)
"
-ForegroundColor
Cyan
}
}
# Show failed installations
$failedInstalls
=
$installationStatus
.
GetEnumerator
()
|
Where-Object
{
$_
.
Value
-eq
"Failed"
}
if
(
$failedInstalls
)
{
Write-Host
"
`n
Failed Installations (May Need Manual Installation):"
-ForegroundColor
Red
$failedInstalls
|
ForEach-Object
{
Write-Host
" -
$(
$_
.
Key
)
"
-ForegroundColor
Red
if
(
$errorMessages
.
ContainsKey
(
$_
.
Key
))
{
Write-Host
" Error:
$(
$errorMessages
[
$_
.
Key
]
)
"
-ForegroundColor
Red
}
}
}
# Show successful updates
$successfulUpdates
=
$updateStatus
.
GetEnumerator
()
|
Where-Object
{
$_
.
Value
-eq
"Success"
}
if
(
$successfulUpdates
)
{
Write-Host
"
`n
Successfully Updated:"
-ForegroundColor
Green
$successfulUpdates
|
ForEach-Object
{
Write-Host
" -
$(
$_
.
Key
)
"
-ForegroundColor
Cyan
}
}
# Show up-to-date applications
$upToDate
=
$updateStatus
.
GetEnumerator
()
|
Where-Object
{
$_
.
Value
-eq
"UpToDate"
}
if
(
$upToDate
)
{
Write-Host
"
`n
Already Up To Date:"
-ForegroundColor
Cyan
$upToDate
|
ForEach-Object
{
Write-Host
" -
$(
$_
.
Key
)
"
-ForegroundColor
Cyan
}
}
# Show failed updates
$failedUpdates
=
$updateStatus
.
GetEnumerator
()
|
Where-Object
{
$_
.
Value
-eq
"Failed"
}
if
(
$failedUpdates
)
{
Write-Host
"
`n
Failed Updates:"
-ForegroundColor
Red
$failedUpdates
|
ForEach-Object
{
Write-Host
" -
$(
$_
.
Key
)
"
-ForegroundColor
Red
if
(
$errorMessages
.
ContainsKey
(
$_
.
Key
))
{
Write-Host
" Error:
$(
$errorMessages
[
$_
.
Key
]
)
"
-ForegroundColor
Red
}
}
}
Write-Host
"
`n
Process completed! Please review the summary above."
-ForegroundColor
Yellow
Write-Host
"For failed installations or updates, please try installing manually."
-ForegroundColor
Yellow
# Keep the terminal open
Write-Host
"
`n
Press any key to exit..."
-ForegroundColor
Cyan
[
System.Console
]::
ReadKey
()
>
$null
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment