Code backup
This commit is contained in:
2026-05-10 16:59:01 +02:00
commit 368d6fafea
796 changed files with 315310 additions and 0 deletions
@@ -0,0 +1,246 @@
##########################
# Writer: Davide Conforti
# Company: PAL s.r.l.
#-------------------------
# Date: 2021/12/01
# v: 1.0
# Reason: Emission
#-------------------------
# Date: 2023/02/20
# v: 1.1
# Reason: Added winget functions
#-------------------------
##########################
#region Functions
function Initialize-Graylog {
Param ([string]$Facility)
if(!(Test-Path -PathType Container -Path "C:\temp\")){
New-Item -ItemType Directory -Force -Path "C:\temp\" | Out-Null
}
$logFile = "C:\temp\$($Facility).log"
if (Test-Path $logFile)
{
Remove-Item $logFile
}
try{
# Installing Graylog Module
if(!(Get-InstalledModule -Name "PSGELF")){
Add-Content -Path $logFile -Value "Installing PSGELF module"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Module -Name PSGELF
Add-Content -Path $logFile -Value "PSGELF module installed!"
}
if(!(Get-Module -Name PSGELF)){
Add-Content -Path $logFile -Value "Importing PSGELF module"
Import-Module -Name PSGELF
Add-Content -Path $logFile -Value "PSGELF module imported!"
}
}
catch{
Add-Content -Path $logFile -Value $_
}
}
function Initialize-Winget {
$logString = "";
try{
if(!(Get-InstalledModule -Name winget)){
$logString += "Installing winget module...`r`n"
$logString += Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
$logString += Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
$logString += Install-Module -Name winget
$logString += "winget module installed!`r`n"
}
if(!(Get-Module -Name winget)){
$logString += "Importing winget module...`r`n"
$logString += Import-Module -Name winget
$logString += "winget module imported!`r`n"
}
}
catch{
$logString += "$_`r`n"
}
return $logString
}
# New
function Initialize-Icinga {
$logString = "";
$module = "icinga-powershell-framework";
try{
if(!(Get-InstalledModule -Name $module)){
$logString += "Installing icinga module...`r`n"
#$logString += Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
$logString += Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
$logString += Install-Module -Name $module
$logString += "Icinga module installed!`r`n"
}
if(!(Get-Module -Name $module)){
$logString += "Importing icinga module...`r`n"
$logString += Import-Module -Name $module
$logString += "Icinga module imported!`r`n"
}
}
catch{
$logString += "$_`r`n"
}
return $logString
}
function Write-Log {
Param ([string]$Facility, [string]$LogString, [int32]$Level = 5)
Initialize-Graylog $Facility
Send-PSGelfUDP -GelfServer "palgraylog01.pal.local" -Port 12204 -ShortMessage $LogString -Level $Level -Facility $Facility
}
function Install-Software {
Param ([string]$Facility, `
[string]$software, `
[string]$version, `
[string]$installPath, `
[string]$installArgument, `
[int32] $timeoutMinutes = 40, `
[bool]$mustUninstallOldVersions = $False, `
[bool]$forceInstallation = $False)
try{
$upToDate = $False
$logString = "`r`n"
$logString += "Checking current installed version for $($software)... (needing $($version))`r`n"
if(!$forceInstallation){
Get-Package -Name "$($software)" |
Foreach-Object {
if([System.Version]$_.Version -ge [System.Version]$version)
{
$logString += "-- Up to date with $($_.Name) v. $($_.Version)`r`n"
$upToDate = $True
}
else
{
if($_)
{
$logString += "-- Found old version: $($_.Name) v. $($_.Version)"
if($mustUninstallOldVersions){
# foreach ($uninstallPath in $uninstallPathArray) {
$logString += " - Uninstalling it..."
Write-Log $Facility $logString
Uninstall-Package $_
#Start-Process -NoNewWindow -Wait -FilePath $uninstallPath -ArgumentList $uninstallArgument
Write-Log $Facility "$($_.Name) v. $($_.Version) successfully uninstalled!"
$logString = ""
# }
}
else{
$logString += " `r `n"
}
}
}
}
}
if($logString){
Write-Log $Facility $logString
}
if(!$upToDate){
Write-Log $Facility "Installing $($software) v. $version"
$timeoutMinutes = $timeoutMinutes * 60
$proc = Start-Process -WindowStyle Hidden -FilePath $installPath -ArgumentList $installArgument -Passthru
$proc | Wait-Process -Timeout $timeoutMinutes -ErrorAction SilentlyContinue
Write-Log $Facility "$($software) installation succesfull!`r`n"
}
}
catch{
Write-Log $Facility $_ 3
}
}
function Set-WingetLocation {
$wingetdir = (Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe" | Sort-Object -Property Path | Select-Object -Last 1)
Set-Location $wingetdir
}
function Get-WingetInstalledSoftware {
Set-WingetLocation
$softwareList = .\winget.exe list --accept-source-agreements | Out-String
return $softwareList
}
function Install-WingetSoftware {
Param ([string]$SoftwareName, `
[string]$SoftwareId, `
[string[]] $InstalledSoftwareList)
Set-WingetLocation
$logString = ""
try{
$logString += "Checking for $($softwareName) installation...`r`n"
if($InstalledSoftwareList -like "*$($softwareId)*") {
$logString += "$($softwareName) already installed!`r`n"
}
else {
$logString += .\winget.exe install -h --accept-package-agreements --accept-source-agreements --id $softwareId | Out-String
$logString += "`r`n$($softwareName) installed!`r`n"
}
}
catch{
$logString += "$_`r`n"
}
return $logString
}
function Install-WingetUpdates {
Set-WingetLocation
$logString = "Checking for updates...`r`n"
try{
$logString += .\winget.exe upgrade -h --all --accept-source-agreements | Out-String
$logString += "Updates installed!`r`n"
}
catch{
$logString += "$_`r`n"
}
return $logString
}
function Add-Machine-EnvVar-PSModulePath($Path) {
$Path = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") + [IO.Path]::PathSeparator + $Path
[Environment]::SetEnvironmentVariable( "PSModulePath", $Path, "Machine" )
}
function Get-IsComputerMemberOf {
Param ([string]$Group)
try {
#Get Computer's DN
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher.Filter = "(&(objectCategory=Computer)(SamAccountname=$($env:COMPUTERNAME)`$))"
$obj = $objSearcher.FindOne()
$Computer = $obj.Properties["distinguishedname"]
#Now get the members of the group
$objSearcher.Filter = "(&(objectCategory=group)(SamAccountname=$Group))"
$obj = $objSearcher.FindOne()
[String[]]$Members = $obj.Properties["member"]
return $Members -contains $Computer
}
catch {
return $False;
}
}
#endregion
@@ -0,0 +1,119 @@
##########################
# Writer: Davide Conforti
# Company: PAL s.r.l.
#-------------------------
# Date: 2023/02/20
# v: 1.0
# Reason: Emission
#-------------------------
##########################
# This is needed to run the software in debug mode
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
# Importing base functions
. \\pal.local\NETLOGON\Powershell\Base-Functions.ps1
$latestDate = "01/12/2021" # First release
$scriptUser = "DC"
$latestVersion = "1.0.0"
$displayName = "Software Installation Script"
#region Initialization
$logString = "`r`n"
$logString += "#################################`r`n"
$logString += "# __________ _____ .____ #`r`n"
$logString += "# \______ \/ _ \ | | #`r`n"
$logString += "# | ___/ /_\ \| | #`r`n"
$logString += "# | | / | \ |___ #`r`n"
$logString += "# |____| \____|__ /_______ \ #`r`n"
$logString += "# \/ \/ #`r`n"
$logString += "# #`r`n"
$logString += "#################################`r`n"
$logString += "`r`n"
$logString += "`r`n"
$logString += " *** $displayName *** `r`n"
$logString += "`r`n"
$logString += " Date: $($latestDate)`r`n"
$logString += " User: $($scriptUser)`r`n"
$logString += " Version: $($latestVersion)`r`n"
$logString += "`r`n"
try {
$logString += "Initializing WinGet...`r`n"
$logString += Initialize-Winget
$logString += "Done!`r`n"
$logString += "Getting the list of installed software...`r`n"
$installedSoftwareList = Get-WingetInstalledSoftware
$logString += "Done!`r`n"
# 7Zip
if(Get-IsComputerMemberOf -Group "PAL SFTW 7ZIP") {
$logString += Install-WingetSoftware -SoftwareName "7Zip" -SoftwareId "7zip.7zip" -InstalledSoftwareList $installedSoftwareList
}
# Adobe Acrobat Reader DC
if(Get-IsComputerMemberOf -Group "PAL SFTW ADOBE READER") {
$logString += Install-WingetSoftware -SoftwareName "Adobe Acrobat Reader DC (64-bit)" -SoftwareId "Adobe.Acrobat.Reader.64-bit" -InstalledSoftwareList $installedSoftwareList
}
# Anydesk
if(Get-IsComputerMemberOf -Group "PAL SFTW ANYDESK") {
$logString += Install-WingetSoftware -SoftwareName "Anydesk" -SoftwareId "AnyDeskSoftwareGmbH.AnyDesk" -InstalledSoftwareList $installedSoftwareList
}
# LibreOffice
if(Get-IsComputerMemberOf -Group "PAL SFTW LIBREOFFICE") {
$logString += Install-WingetSoftware -SoftwareName "Libreoffice" -SoftwareId "TheDocumentFoundation.LibreOffice" -InstalledSoftwareList $installedSoftwareList
}
# Mozilla Firefox
if(Get-IsComputerMemberOf -Group "PAL SFTW FIREFOX") {
$logString += Install-WingetSoftware -SoftwareName "Mozilla Firefox" -SoftwareId "Mozilla.Firefox" -InstalledSoftwareList $installedSoftwareList
}
# Mozilla Thunderbird
if(Get-IsComputerMemberOf -Group "PAL SFTW THUNDERBIRD") {
$logString += Install-WingetSoftware -SoftwareName "Mozilla Thunderbird" -SoftwareId "Mozilla.Thunderbird" -InstalledSoftwareList $installedSoftwareList
}
# Nextcloud Desktop
if(Get-IsComputerMemberOf -Group "PAL SFTW NEXTCLOUD DESKTOP") {
$logString += Install-WingetSoftware -SoftwareName "Nextcloud Desktop" -SoftwareId "Nextcloud.NextcloudDesktop" -InstalledSoftwareList $installedSoftwareList
}
# Notepad++
if(Get-IsComputerMemberOf -Group "PAL SFTW NOTEPAD PLUS PLUS") {
$logString += Install-WingetSoftware -SoftwareName "Notepad++" -SoftwareId "Notepad++.Notepad++" -InstalledSoftwareList $installedSoftwareList
}
# VideoLAN VLC Media Plauer
if(Get-IsComputerMemberOf -Group "PAL SFTW VLC") {
$logString += Install-WingetSoftware -SoftwareName "VideoLAN VLC" -SoftwareId "VideoLAN.VLC" -InstalledSoftwareList $installedSoftwareList
}
# Microsoft Visual Studio 7
if(Get-IsComputerMemberOf -Group "PAL SFTW VSC") {
$logString += Install-WingetSoftware -SoftwareName "Microsoft - Visual Studio Code" -SoftwareId "Microsoft.VisualStudioCode" -InstalledSoftwareList $installedSoftwareList
}
# Microsoft DotNet Runtime 7
$logString += Install-WingetSoftware -SoftwareName "Microsoft .NET Desktop Runtime 7" -SoftwareId "Microsoft.DotNet.DesktopRuntime.7" -InstalledSoftwareList $installedSoftwareList
# Microsoft WebView 2
$logString += Install-WingetSoftware -SoftwareName "Microsoft - WebView2 Runtime" -SoftwareId "Microsoft.EdgeWebView2Runtime" -InstalledSoftwareList $installedSoftwareList
# Upgrade all software
$logString += Install-WingetUpdates
}
catch {
$logString += "$_`r`n"
}
Write-Log $displayName $logString