Update-Firefox: Added ConfigFile and Logging, and improved the script structure
This commit is contained in:
parent
c4284004b6
commit
078cf74927
@ -1,77 +1,829 @@
|
|||||||
# Update-Firefox
|
# Update-Firefox
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# This Script installs the current Firefox version
|
# This Script installs the newest Firefox version
|
||||||
#
|
#
|
||||||
# Returns: -
|
# Returns: -
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Copyright (c) 2024 by Digital Data GmbH
|
# Copyright (c) 2024 by Digital Data GmbH
|
||||||
#
|
#
|
||||||
# Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
# Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
||||||
# Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
# Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
# Creation Date / Author: 04.11.2024 / MK
|
# Creation Date / Author: 04.11.2024 / MK
|
||||||
# Version Date / Editor: 04.11.2024 / MK
|
# Version Date / Editor: 23.11.2024 / MK
|
||||||
# Version Number: 1.0.0.0
|
# Version Number: 1.1.0.0
|
||||||
|
|
||||||
#Requires –Version 4.0
|
#Requires –Version 4.0
|
||||||
|
|
||||||
Clear-Host
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
######################################## check for arguments ##########################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
################################## add additional buildin assemblys ###################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#Add-Type -AssemblyName System.Windows.Forms -ErrorAction Stop
|
||||||
|
#Add-Type -AssemblyName PresentationCore -ErrorAction Stop
|
||||||
|
#Add-Type -AssemblyName PresentationFramework -ErrorAction Stop
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
############################################ set variables ############################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
Set-Variable -Scope Global -Name ScriptName -Value (($MyInvocation.MyCommand.Name) -split "\.")[0].ToString()
|
||||||
|
Set-Variable -Scope Global -Name ScriptPath -Value (Split-Path ($MyInvocation.MyCommand.Path))
|
||||||
|
Set-Variable -Scope Global -Name ConfigFile -Value (Get-ChildItem -Path "$ScriptPath" -Recurse -Filter "$ScriptName`_Settings.ini" -File -Force).FullName
|
||||||
|
Set-Variable -Scope Global -Name ConfigFileContent -Value $NULL
|
||||||
|
Set-Variable -Scope Global -Name Timestamp1 -Value $(Get-Date -Format 'ddMMyyyy')
|
||||||
|
Set-Variable -Scope Global -Name Timestamp2 -Value $(Get-Date -Format 'ddMMyyyy_HHmmss')
|
||||||
|
Set-Variable -Scope Global -Name Timestamp3 -Value $(Get-Date -Format 'ddMMyyyy_HHmmssffff')
|
||||||
|
Set-Variable -Scope Global -Name Timestamp4 -Value $(Get-Date -Format 'yyyyMMdd HH:mm:ss.fff')
|
||||||
|
Set-Variable -Scope Global -Name LogFile -Value "$ScriptName`_$Timestamp2.log"
|
||||||
|
Set-Variable -Scope Global -Name LogFileKeepTime -Value 60
|
||||||
|
Set-Variable -Scope Global -Name LogPath -Value $NULL
|
||||||
|
Set-Variable -Scope Global -Name Module -Value $NULL
|
||||||
|
Set-Variable -Scope Global -Name Modules -Value ("Read-ConfigFile2","Write-LogFile","Remove-Item-withLogging")
|
||||||
|
Set-Variable -Scope Global -Name ModuleOverrideSourcePath -Value $NULL
|
||||||
|
Set-Variable -Scope Global -Name ModuleDefaultSourcePath -Value "P:\Skriptentwickung\current\Modules"
|
||||||
|
Set-Variable -Scope Global -Name ModuleHKLMRegistryPath -Value "HKLM:\SOFTWARE\Digital Data\Modules"
|
||||||
|
Set-Variable -Scope Global -Name ModuleHKCURegistryPath -Value "HKCU:\SOFTWARE\Digital Data\Modules"
|
||||||
|
|
||||||
|
Set-Variable -Scope Global -Name VersionURL -Value "https://product-details.mozilla.org/1.0/firefox_versions.json"
|
||||||
|
Set-Variable -Scope Global -Name DownloadURL -Value "https://download-installer.cdn.mozilla.net/pub/firefox/releases/%NewFirefoxVersion%/win64/de/Firefox%20Setup%20%NewFirefoxVersion%.msi"
|
||||||
|
Set-Variable -Scope Global -Name InstallPath -Value "D:\ProgramFiles\Mozilla Firefox"
|
||||||
|
Set-Variable -Scope Global -Name CurrentFirefoxVersion -Value 0
|
||||||
|
Set-Variable -Scope Global -Name NewFirefoxVersion -Value 0
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
############################################ set functions ############################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
Function Import-CustomModule {
|
||||||
|
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Function will load external - additional - PowerShell Modules into current PSSession.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
By working with Modules, this Function is necessary to load external Modul Functions into the current PowerShell Session.
|
||||||
|
In a productive Enviroment it is recommanded to let this Function set the Registry Key in HKLM for the ModuleSourcePath.
|
||||||
|
In develepment and Test Enviroment it is possible, to work with distributed Folders with different Modules. Therefor the Parameter
|
||||||
|
"ModuleOverrideSourcePath" and the preset Variable "ModuleDefaultSourcePath" are made for.
|
||||||
|
After a successful Import of a Module, Function will Return $True, otherwise a $False.
|
||||||
|
|
||||||
|
.REQUIREMENT General
|
||||||
|
PowerShell V3
|
||||||
|
|
||||||
|
.REQUIREMENT Assembly
|
||||||
|
System.Windows.Forms, PresentationCore, PresentationFramework
|
||||||
|
|
||||||
|
.REQUIREMENT Variables
|
||||||
|
ModuleOverrideSourcePath, ModuleName, Path, Paths, PathTest, FileTest, Result
|
||||||
|
|
||||||
|
.REQUIREMENT Variables preSet
|
||||||
|
ScriptName, ScriptPath, ModuleDefaultSourcePath (optional)
|
||||||
|
|
||||||
|
.REQUIREMENT Functions
|
||||||
|
<NONE>
|
||||||
|
|
||||||
|
.VERSION
|
||||||
|
1.2.0.0 / 09.11.2024
|
||||||
|
|
||||||
|
.PARAMETER ModuleName
|
||||||
|
Give the Module Name, you want to load into the current PSSession (without File-Extension).
|
||||||
|
|
||||||
|
.PARAMETER ModuleOverrideSourcePath
|
||||||
|
Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.
|
||||||
|
|
||||||
|
.PARAMETER ModuleFileExtensions
|
||||||
|
Optional Parameter. Give the Module File-Extension (regular: "psm1" or "dll") without a dot ("."), this is just for the checking routine, not the Import itself.')]
|
||||||
|
|
||||||
|
.PARAMETER Force
|
||||||
|
Optional Parameter. By using the Force Parameter, Module will be unload and reload.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Import-CustomModule -ModuleName Write-LogFile -ModuleFileExtensions psm1
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Import-CustomModule -ModuleName Write-LogFile -Force
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Import-CustomModule -ModuleName Write-LogFile -ModuleFileExtensions psm1 -ModuleOverrideSourcePath D:\ScriptFiles\Modules
|
||||||
|
#>
|
||||||
|
|
||||||
|
Param (
|
||||||
|
|
||||||
|
[Parameter(Position=0,Mandatory=$True,ValueFromPipeline=$True,HelpMessage='Give the ModuleName, you want to load into the current PSSession (without File-Extension)')]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[String]$ModuleName,
|
||||||
|
|
||||||
|
[Parameter(Position=1,Mandatory=$False,HelpMessage='Optional Parameter. By giving the ModuleOverrideSourcePath, Function will not check other Paths for the Function you want to load.')]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[String]$ModuleOverrideSourcePath,
|
||||||
|
|
||||||
|
[Parameter(Position=2,Mandatory=$False,HelpMessage='Optional Parameter. Give the Module File-Extension (regular: "psm1" or "dll") without a dot ("."), this is just for the checking routine, not the Import itself.')]
|
||||||
|
[ValidateSet("psm1","dll")]
|
||||||
|
[Array]$ModuleFileExtensions = @("psm1","dll"),
|
||||||
|
|
||||||
|
[Parameter(Position=3,Mandatory=$False,HelpMessage='Optional Parameter. By using the Force Parameter, Module will be unload and reload.')]
|
||||||
|
[Switch]$Force
|
||||||
|
|
||||||
|
) #end param
|
||||||
|
|
||||||
|
Process {
|
||||||
|
|
||||||
|
#Clear Error Variable
|
||||||
|
$error.clear()
|
||||||
|
|
||||||
|
#Loop for every possible File Extension (eg. psm1 and dll)
|
||||||
|
FOREACH ($ModuleFileExtension in $ModuleFileExtensions) {
|
||||||
|
|
||||||
|
#If FileExtension was given, remove it! Because otherwise "Import-Module" Function will have trouble importing.
|
||||||
|
$ModuleName = $ModuleName -Replace("\.(\w{3}|\w{4})$","")
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: You want to load Module $ModuleName.$ModuleFileExtension"
|
||||||
|
|
||||||
|
IF ((([String]::IsNullOrWhiteSpace($ScriptName) -ne $True) -and ([String]::IsNullOrEmpty($ScriptName) -ne $True)) -and (([String]::IsNullOrWhiteSpace($ScriptPath) -ne $True) -and ([String]::IsNullOrEmpty($ScriptPath) -ne $True))) {
|
||||||
|
|
||||||
|
#Try this if $ModuleOverrideSourcePath was given by calling the function
|
||||||
|
IF ((([String]::IsNullOrWhiteSpace($ModuleOverrideSourcePath)) -ne $True) -and (([String]::IsNullOrEmpty($ModuleOverrideSourcePath)) -ne $True)) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Function has been called with 'ModuleOverrideSourcePath' Parameter input!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Testing for existence: $ModuleOverrideSourcePath\$ModuleName.$ModuleFileExtension"
|
||||||
|
$FileTest = Test-Path -Path "$ModuleOverrideSourcePath\$ModuleName.$ModuleFileExtension" -PathType Leaf
|
||||||
|
|
||||||
|
IF ($FileTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: $ModuleOverrideSourcePath and ModuleName seems to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to import Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
$Result = Import-Module $ModuleOverrideSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
IF ("$Result" -eq "$ModuleName") {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Successfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
Return $True
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Error "DEBUG Info - Import-CustomModule: Unsuccessfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
Return $False
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Error while importing the Module:"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: $ModuleName"
|
||||||
|
Write-Host $Error
|
||||||
|
Return $False
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ModuleOverrideSourcePath and/or ModuleName seems not to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Cannot load Module, please check your input!"
|
||||||
|
Return $False
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE { #If $ModuleOverrideSourcePath was not given, try to find a matching folder
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Function has been called without 'ModuleOverrideSourcePath' Parameter input!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to find Module Files on some Places of this Computer."
|
||||||
|
|
||||||
|
#Set dynamic Array for locations Modul Path could be, even for some testing.
|
||||||
|
#The first value of the array is just a dummy and will never be used -but keep it for the array value starting with 0!
|
||||||
|
[System.Collections.ArrayList]$Paths = @()
|
||||||
|
Write-Host ""
|
||||||
|
$Paths.Add("$env:systemroot\") | Out-Null
|
||||||
|
|
||||||
|
IF (([String]::IsNullOrEmpty($ModuleDefaultSourcePath)) -or ([String]::IsNullOrWhiteSpace($ModuleDefaultSourcePath))) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ModuleDefaultSourcePath was not set! That could be a normal behavior in productive enviroment!"
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (1): $ModuleDefaultSourcePath" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$ModuleDefaultSourcePath") | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
IF ([String]::IsNullOrEmpty($ScriptPath) -or ([String]::IsNullOrWhiteSpace($ScriptPath))) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ScriptPath is invalid! That is terrifying! How could that be???"
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (2): $ScriptPath" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$ScriptPath") | Out-Null
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (3): $($ScriptPath+"\Module")" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$($ScriptPath+"\Module")") | Out-Null
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (4): $($ScriptPath+"\Modules")" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$($ScriptPath+"\Modules")") | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
IF (([String]::IsNullOrEmpty((Get-Item $ScriptPath).Parent.FullName)) -or ([String]::IsNullOrWhiteSpace((Get-Item $ScriptPath).Parent.FullName))) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ScriptPath has no Parent Folders!"
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (5): $((Get-Item $ScriptPath).Parent.FullName)" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$((Get-Item $ScriptPath).Parent.FullName)") | Out-Null
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (6): $(((Get-Item $ScriptPath).Parent.FullName)+"\Module")" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$(((Get-Item $ScriptPath).Parent.FullName)+"\Module")") | Out-Null
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (7): $(((Get-Item $ScriptPath).Parent.FullName)+"\Modules")" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$(((Get-Item $ScriptPath).Parent.FullName)+"\Modules")") | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
IF (([String]::IsNullOrEmpty($((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath))) -or ([String]::IsNullOrWhiteSpace($((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)))) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ModuleSourcePath was not set to Windows Registry (HKLM)!"
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (8): $((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$((Get-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)") | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
IF (([String]::IsNullOrEmpty($((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath))) -or ([String]::IsNullOrWhiteSpace($((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)))) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ModuleSourcePath was not set to Windows Registry (HKCU)!"
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Possible Path (8): $((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)" -ErrorAction SilentlyContinue
|
||||||
|
$Paths.Add("$((Get-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -ErrorAction SilentlyContinue).ModuleSourcePath)") | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
[Int]$Counter = 0
|
||||||
|
[String]$ModuleSourcePath = $Null
|
||||||
|
|
||||||
|
#Loop for multiple Pathtests - for each Path, where Module files could be
|
||||||
|
DO {
|
||||||
|
|
||||||
|
$Counter++ | Out-Null
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Testing mutiple Paths ( $Counter of"($($Paths.Count)-1)") for existence, now testing:"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: $($Paths[$Counter])"
|
||||||
|
|
||||||
|
IF ((([String]::IsNullOrWhiteSpace($($Paths[$Counter]))) -ne $True) -and (([String]::IsNullOrEmpty($($Paths[$Counter])) -ne $True))) {
|
||||||
|
|
||||||
|
$PathTest = (Test-Path $($Paths[$Counter]) -ErrorAction SilentlyContinue)
|
||||||
|
|
||||||
|
IF ($PathTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Yes, Path seems to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Lets check, if there are any Module Files, in it."
|
||||||
|
|
||||||
|
$FileTest = Get-ChildItem -Path $($Paths[$Counter]) -Filter *.$ModuleFileExtension
|
||||||
|
|
||||||
|
IF ($($FileTest.count) -gt 0) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Found $($FileTest.count) $ModuleFileExtension Module Files in Path!"
|
||||||
|
Set-Variable -Name ModuleSourcePath -Value $($Paths[$Counter]) -Scope local
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Found no $ModuleFileExtension Module Files in Path!"
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: No, Path seems not to exist."
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Path seems to be invalid!"
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} #end do
|
||||||
|
|
||||||
|
UNTIL ($Counter -ge ($($Paths.Count)-1) -or ($ModuleSourcePath -eq $($Paths[$Counter])))
|
||||||
|
|
||||||
|
IF ($ModuleSourcePath -eq $($Paths[$Counter])) {
|
||||||
|
|
||||||
|
$FileTest = (Test-Path -Path $ModuleSourcePath\$ModuleName.$ModuleFileExtension -PathType Leaf -ErrorAction SilentlyContinue)
|
||||||
|
|
||||||
|
IF ($FileTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to import Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
$Result = Import-Module $ModuleSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
IF ("$Result" -eq "$ModuleName") {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Successfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||||
|
Return $True
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Error "DEBUG Info - Import-CustomModule: Unsuccessfully loaded Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
Return $False
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Loading Module: $ModuleName went wrong."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this error!"
|
||||||
|
Write-Host $Error
|
||||||
|
Return $False
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Module does not exist!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Skipping: $ModuleName.$ModuleFileExtension"
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Cant locate Module Files automaticlly!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Please select Folder in Dialog."
|
||||||
|
|
||||||
|
#Prepare Folder Browser Dialog, to choose the Directory with the .psm1 Files.
|
||||||
|
$FolderBrowserDialog = New-Object System.Windows.Forms.FolderBrowserDialog
|
||||||
|
$FolderBrowserDialog.Rootfolder = "Desktop"
|
||||||
|
$FolderBrowserDialog.Description = "Please, choose the Folder, where the Module ""$ModuleName.$ModuleFileExtension"" is stored."
|
||||||
|
$FolderBrowserDialog.SelectedPath = "$ScriptPath"
|
||||||
|
$FolderBrowserDialog.ShowNewFolderButton = $True
|
||||||
|
|
||||||
|
DO {
|
||||||
|
|
||||||
|
#Now show the Folder Browser, if neccessary in a loop
|
||||||
|
$FolderBrowserDialogShow = $FolderBrowserDialog.ShowDialog()
|
||||||
|
|
||||||
|
#By pressing the OK Button..
|
||||||
|
If ($FolderBrowserDialogShow -eq "OK") {
|
||||||
|
|
||||||
|
#Save selected folder path in the variable
|
||||||
|
$ModuleSourcePath = ($FolderBrowserDialog.SelectedPath)
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: You choose: $ModuleSourcePath"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: ...testing, if Module ""$ModuleName.$ModuleFileExtension"" can be found there."
|
||||||
|
|
||||||
|
$FileTest = (Test-Path $ModuleSourcePath\$ModuleName.$ModuleFileExtension -PathType Leaf -ErrorAction SilentlyContinue)
|
||||||
|
|
||||||
|
IF ($FileTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Module seems to exist, in the selected Folder."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Now trying to load Module: $ModuleName.$ModuleFileExtension"
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
$Result = Import-Module $ModuleSourcePath\$ModuleName -Verbose -DisableNameChecking -Scope Global -Force:$Force -PassThru -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
IF ("$Result" -eq "$ModuleName") {
|
||||||
|
|
||||||
|
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||||
|
|
||||||
|
$MessageBoxBody = "Module: $ModuleName.$ModuleFileExtension - successsfully loaded into current PSSession!"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Information"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||||
|
|
||||||
|
#Set new default path for next foreach loop
|
||||||
|
Set-Variable -Name ModuleDefaultSourcePath -Value $ModuleSourcePath -Scope Global
|
||||||
|
Set-Variable -Name ModuleOverrideSourcePath -Value $ModuleSourcePath -Scope Global
|
||||||
|
Set-Variable -Name ModuleSourcePath -Value $ModuleSourcePath -Scope Global
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
$MessageBoxBody = "Module: $ModuleName.$ModuleFileExtension - cannot load into current PSSession!"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Warning"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||||
|
|
||||||
|
} #end If/else
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Loading Module: $ModuleName.$ModuleFileExtension went wrong."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this error!"
|
||||||
|
Write-Host $Error
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Module seems not to exist, in the selected Folder."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Please, select another one! ...this Time the right!"
|
||||||
|
|
||||||
|
$MessageBoxBody = "Module seems not to exist, in the selected Folder! Please, select another one!"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Warning"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon) | Out-Null
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE { #If you didnt pressed the OK Button..
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Operation cancelled by user."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} #end do
|
||||||
|
|
||||||
|
#Variable "$?" is $True when last operation was ok
|
||||||
|
UNTIL ((($FileTest -eq $True) -and ($? -eq $True)) -or ($FolderBrowserDialogShow -eq "Cancel"))
|
||||||
|
|
||||||
|
IF (([String]::IsNullOrWhiteSpace($ModuleSourcePath) -ne $True) -and ([String]::IsNullOrEmpty($ModuleSourcePath) -ne $True)) {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Should ModuleSourcePath written to Windows Registry?"
|
||||||
|
|
||||||
|
$MessageBoxBody = "Would you like to save the ModulePath to the Windows Registry?"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "YesNo"
|
||||||
|
$MessageBoxIcon = "Question"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
|
||||||
|
IF ($MessageBox -eq 'Yes') {
|
||||||
|
|
||||||
|
$PathTest = (Test-Path -Path "$ModuleHKLMRegistryPath" -ErrorAction SilentlyContinue)
|
||||||
|
$MessageBox = $NULL
|
||||||
|
|
||||||
|
IF ($PathTest -eq $False) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems not to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKLM."
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
New-Item -Path "$ModuleHKLMRegistryPath" -Force -ErrorAction Stop | Out-Null
|
||||||
|
New-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host $Error
|
||||||
|
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Check your access rights! To bypass this issue you can write the ModuleSourcePath to User Registry (HKCU). Would you?"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "YesNo"
|
||||||
|
$MessageBoxIcon = "Question"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSEIF ($PathTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKLM."
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
Set-ItemProperty -Path "$ModuleHKLMRegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host $Error
|
||||||
|
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Check your access rights! To Bypass Error: Write ModuleSource Path to User Registry (HKCU)?"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "YesNo"
|
||||||
|
$MessageBoxIcon = "Question"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end if/elseif/else
|
||||||
|
|
||||||
|
#Block for trying to write the ModuleSourcePath to the User Registry, if System Registry failed.
|
||||||
|
IF ($MessageBox -eq 'Yes') {
|
||||||
|
|
||||||
|
$PathTest = (Test-Path -Path "$ModuleHKCURegistryPath" -ErrorAction SilentlyContinue)
|
||||||
|
$MessageBox = $NULL
|
||||||
|
|
||||||
|
IF ($PathTest -eq $False) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems not to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKCU."
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
New-Item -Path "$ModuleHKCURegistryPath" -Force -ErrorAction Stop | Out-Null
|
||||||
|
New-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host $Error
|
||||||
|
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Not even to User Registry! Check your access rights! Exiting now.."
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Warning"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSEIF ($PathTest -eq $True) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Registry Key seems to exist."
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Trying to write ModuleSourcepath to HKCU."
|
||||||
|
|
||||||
|
Try {
|
||||||
|
|
||||||
|
Set-ItemProperty -Path "$ModuleHKCURegistryPath" -Name ModuleSourcePath -Value $ModuleSourcePath -ErrorAction Stop | Out-Null
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
|
||||||
|
Write-Host $Error
|
||||||
|
$MessageBoxBody = "Could not save ModuleSourcePath to Windows Registry! Not even to User Registry! Check your access rights! Exiting now.."
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Warning"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end if/elseif/else
|
||||||
|
|
||||||
|
} #end if
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: You choose, not to save the ModuleSourcePath to the Windows Registry!"
|
||||||
|
|
||||||
|
$MessageBoxBody = "You choose, not to save the ModuleSourcePath to the Windows Registry!"
|
||||||
|
$MessageBoxTitle = "ScriptName: $ScriptName - Module/Section: Import-CustomModule"
|
||||||
|
$MessageBoxButtonType = "OK"
|
||||||
|
$MessageBoxIcon = "Warning"
|
||||||
|
$MessageBox = [Windows.Forms.MessageBox]::Show($MessageBoxBody,$MessageBoxTitle,$MessageBoxButtonType,$MessageBoxIcon)
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Something went wrong, by getting the ModuleSourcePath!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Exiting Script, because of this!"
|
||||||
|
exit
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} #end if/ else
|
||||||
|
|
||||||
|
} ELSE {
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Required Variables (ScriptName and ScriptPath) were not set!"
|
||||||
|
Write-Host "DEBUG Info - Import-CustomModule: Module Import is unvailable without this Variables!"
|
||||||
|
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} #end foreach
|
||||||
|
|
||||||
|
} #end process
|
||||||
|
|
||||||
|
} #end function
|
||||||
Function Get-CurrentFirefoxVersion {
|
Function Get-CurrentFirefoxVersion {
|
||||||
$CurrentFirefoxVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -Name "(default)" -ErrorAction SilentlyContinue)."(default)"
|
Try {
|
||||||
Write-Host "Current Firefox Version: $CurrentFirefoxVersion"
|
$CurrentFirefoxVersion = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Mozilla\Mozilla Firefox" -Name "(default)" -ErrorAction Stop)."(default)"
|
||||||
Return $CurrentFirefoxVersion
|
Write-Logfile -LogLine "Currently installed Firefox Version: $CurrentFirefoxVersion"
|
||||||
} #end function
|
Return $CurrentFirefoxVersion
|
||||||
|
} Catch {
|
||||||
|
Write-Logfile -LogLine "Firefox seems not to be installed!"
|
||||||
|
Return 0
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
|
} #end function
|
||||||
Function Get-NewFirefoxVersion {
|
Function Get-NewFirefoxVersion {
|
||||||
# Fetch the content of the Firefox release notes page
|
Try {
|
||||||
$response = Invoke-WebRequest -Uri "https://www.mozilla.org/de/firefox/notes/"
|
|
||||||
$pageContent = $response.Content
|
$WebRequestResult = Invoke-WebRequest -Uri $VersionURL -ErrorAction Stop
|
||||||
|
If ($WebRequestResult.StatusCode -eq "200") {
|
||||||
|
Write-Logfile -LogLine "Connection to server established!"
|
||||||
|
|
||||||
|
$RestMethodResult = Invoke-RestMethod -Uri $VersionURL -ErrorAction Stop
|
||||||
|
Write-Logfile -LogLine "Software Version on server retrived!"
|
||||||
|
|
||||||
|
IF ($RestMethodResult.LATEST_FIREFOX_VERSION -gt "0" ) {
|
||||||
|
[version]$NewFirefoxVersion = $($RestMethodResult.LATEST_FIREFOX_VERSION)
|
||||||
|
Write-Logfile -LogLine "Latest Firefox Version: $NewFirefoxVersion"
|
||||||
|
Return $NewFirefoxVersion.ToString()
|
||||||
|
} else {
|
||||||
|
Write-Logfile -LogLine "Could not find the Firefox version number on the release notes page."
|
||||||
|
Return 0
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} Else {
|
||||||
|
Write-Logfile -LogLine "Connection to server failed!"
|
||||||
|
Write-Logfile -LogLine "StatusCode: $($WebRequestResult.StatusCode)"
|
||||||
|
Write-Logfile -LogLine "StatusDescription: $($WebRequestResult.StatusDescription)"
|
||||||
|
Return 0
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
|
} Catch {
|
||||||
|
Write-Logfile -LogLine "Error while getting the new software version from the server!"
|
||||||
|
Write-Logfile -LogLine $Error[0].ToString()
|
||||||
|
Return 0
|
||||||
|
} #end try/catch
|
||||||
|
|
||||||
# Extract the version number using a regular expression
|
|
||||||
if ($pageContent -match '<title>Firefox\s+([0-9]+\.[0-9]+),\s+See\s+All\s+New\s+Features,\s+Updates\s+and\s+Fixes<\/title>') {
|
|
||||||
$NewFirefoxVersion = $matches[1]
|
|
||||||
Write-Host "Latest Firefox Version: $latestVersion"
|
|
||||||
Return $NewFirefoxVersion
|
|
||||||
} else {
|
|
||||||
Write-Host "Could not find the Firefox version number on the release notes page."
|
|
||||||
Return $NULL
|
|
||||||
}
|
|
||||||
} #end function
|
} #end function
|
||||||
|
|
||||||
Function Update-NewFirefoxVersion {
|
Function Update-NewFirefoxVersion {
|
||||||
Param ($NewFirefoxVersion)
|
Param ($NewFirefoxVersion, $DownloadURL)
|
||||||
|
|
||||||
# Define the URL for the latest Firefox installer
|
|
||||||
$NewFirefoxVersionURL = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/$NewFirefoxVersion/win64/de/Firefox%20Setup%20$NewFirefoxVersion.msi"
|
|
||||||
|
|
||||||
# Use Invoke-WebRequest to download the installer
|
|
||||||
Write-Host "Downloading Firefox Version $NewFirefoxVersion..."
|
|
||||||
Invoke-WebRequest -Uri $NewFirefoxVersionURL -OutFile "$env:TEMP\Firefox$NewFirefoxVersion.msi"
|
|
||||||
|
|
||||||
Try {
|
Try {
|
||||||
$FirefoxProcess = Get-Process -Name "firefox" -ErrorAction SilentlyContinue
|
# Define the URL for the latest Firefox installer
|
||||||
If ($FirefoxProcess) {Stop-Process -Name "firefox" -Force -ErrorAction Stop}
|
$NewFirefoxVersionURL = $DownloadURL -replace("%NewFirefoxVersion%",$NewFirefoxVersion)
|
||||||
Write-Host "Installing Firefox Version $NewFirefoxVersion, please wait..."
|
$NewFirefoxVersionSetup = "$env:TEMP\Firefox$NewFirefoxVersion.msi"
|
||||||
$ArgumentList = "/i $env:TEMP\Firefox$NewFirefoxVersion.msi INSTALL_DIRECTORY_PATH=""D:\ProgramFiles\Mozilla Firefox"" /quiet"
|
|
||||||
Start-Process -FilePath "msiexec.exe" -ArgumentList $ArgumentList -Wait
|
# Use Invoke-WebRequest to download the installer
|
||||||
|
Write-Logfile -LogLine "Downloading Firefox Version $NewFirefoxVersion..."
|
||||||
|
Invoke-WebRequest -Uri $NewFirefoxVersionURL -OutFile $NewFirefoxVersionSetup -ErrorAction Stop
|
||||||
|
|
||||||
|
IF (Test-Path -Path $NewFirefoxVersionSetup -PathType Leaf -ErrorAction SilentlyContinue) {
|
||||||
|
|
||||||
|
$FirefoxProcess = Get-Process -Name "firefox" -ErrorAction SilentlyContinue
|
||||||
|
If ($FirefoxProcess) {Stop-Process -Name "firefox" -Force -ErrorAction Stop}
|
||||||
|
|
||||||
|
Write-Logfile -LogLine "Installing Firefox Version $NewFirefoxVersion, please wait..."
|
||||||
|
$ArgumentList = "/i $NewFirefoxVersionSetup INSTALL_DIRECTORY_PATH=""$InstallPath"" /quiet"
|
||||||
|
Start-Process -Verb runAs -FilePath "msiexec.exe" -ArgumentList $ArgumentList -Wait -ErrorAction Stop
|
||||||
|
|
||||||
|
} Else {
|
||||||
|
Write-Logfile -LogLine "Cannot find setup file!"
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
} Catch {
|
} Catch {
|
||||||
Write-Host "ERROR!"
|
Write-Logfile -LogLine "ERROR!"
|
||||||
Write-Host $Error[0].ToString()
|
Write-Logfile -LogLine $Error[0].ToString()
|
||||||
|
|
||||||
} Finally {
|
} Finally {
|
||||||
Write-Host "Cleaning Up!"
|
Write-Logfile -LogLine "Cleaning Up!"
|
||||||
Remove-Item "$env:TEMP\Firefox$NewFirefoxVersion.msi" -Force
|
Remove-Item "$env:TEMP\Firefox$NewFirefoxVersion.msi" -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
} #end try/catch/finally
|
} #end try/catch/finally
|
||||||
|
|
||||||
} #end function
|
} #end function
|
||||||
|
|
||||||
$CurrentFirefoxVersion = Get-CurrentFirefoxVersion
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
$NewFirefoxVersion = Get-NewFirefoxVersion
|
########################################### preparing part ############################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#Clear Console Content
|
||||||
|
Clear-Host
|
||||||
|
|
||||||
|
#Load external Modules - use Force ( -Force) Parameter, to reload in every run
|
||||||
|
FOREACH ($Module in $Modules) {
|
||||||
|
|
||||||
|
$Result = Import-CustomModule -ModuleName $Module -Force
|
||||||
|
|
||||||
|
IF ($Result -eq $False) {
|
||||||
|
|
||||||
|
Write-Host "DEBUG Info: Module: $Module was not successful been loaded!"
|
||||||
|
Write-Host "DEBUG Info: Please load the Module and try again, running this Function/Module!"
|
||||||
|
Write-Host "DEBUG Info: Exiting, because of this Issue."
|
||||||
|
Write-Host $Error
|
||||||
|
EXIT
|
||||||
|
|
||||||
|
} #end if
|
||||||
|
|
||||||
|
} #end foreach
|
||||||
|
|
||||||
|
#Read ConfigFile and load its content into a Object
|
||||||
|
[OBJECT]$ConfigFileContent = Read-ConfigFile2 -ConfigFile $ConfigFile
|
||||||
|
|
||||||
|
#Allocate Variable Values, depending on the read ConfigFile
|
||||||
|
[ARRAY]$LogPaths = $ConfigFileContent."LogPath_$($ConfigFileContent.LogPath[0])"
|
||||||
|
[STRING]$LogFileKeepTime = $ConfigFileContent."LogFileKeepTime_$($ConfigFileContent.LogFileKeepTime[0])"
|
||||||
|
|
||||||
|
[STRING]$VersionURL = $ConfigFileContent."VersionURL_$($ConfigFileContent.VersionURL[0])"
|
||||||
|
[STRING]$DownloadURL = $ConfigFileContent."DownloadURL_$($ConfigFileContent.DownloadURL[0])"
|
||||||
|
[STRING]$InstallPath = $ConfigFileContent."InstallPath_$($ConfigFileContent.InstallPath[0])"
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
############################################# main part ###############################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#Clear Error Variable
|
||||||
|
$Error.Clear() | Out-Null
|
||||||
|
|
||||||
|
#Clear Console Output
|
||||||
|
Clear-Host
|
||||||
|
|
||||||
|
Write-Host " "
|
||||||
|
Write-Logfile -LogLine "********************************************************************************"
|
||||||
|
Write-Logfile -LogLine "Program Startup: $ScriptName on $env:COMPUTERNAME,"
|
||||||
|
Write-Logfile -LogLine "from Account $env:USERDOMAIN\$env:USERNAME."
|
||||||
|
Write-Logfile -LogLine "********************************************************************************"
|
||||||
|
|
||||||
|
Write-Logfile -LogLine " "
|
||||||
|
|
||||||
|
IF (($VersionURL) -and ($DownloadURL) -and ($InstallPath)) {
|
||||||
|
Write-Logfile -LogLine "All required Variables are set for this Script."
|
||||||
|
|
||||||
|
$CurrentFirefoxVersion = Get-CurrentFirefoxVersion
|
||||||
|
$NewFirefoxVersion = Get-NewFirefoxVersion
|
||||||
|
|
||||||
|
If ($NewFirefoxVersion -gt $CurrentFirefoxVersion) {
|
||||||
|
Write-Logfile -LogLine "Install or Update is neccessary!"
|
||||||
|
Update-NewFirefoxVersion -NewFirefoxVersion $NewFirefoxVersion -DownloadURL $DownloadURL
|
||||||
|
Write-Logfile -LogLine "Install or Update is completed!"
|
||||||
|
Get-CurrentFirefoxVersion | Out-Null
|
||||||
|
} Else {
|
||||||
|
Write-Logfile -LogLine "No Install or Update is neccessary!"
|
||||||
|
} #end if/else
|
||||||
|
|
||||||
If ($NewFirefoxVersion -gt $CurrentFirefoxVersion) {
|
|
||||||
Write-Host "Install or Update is neccessary!"
|
|
||||||
Update-NewFirefoxVersion -NewFirefoxVersion $NewFirefoxVersion
|
|
||||||
Write-Host "Install or Update is completed!"
|
|
||||||
} Else {
|
} Else {
|
||||||
Write-Host "No Install or Update is neccessary!"
|
Write-Logfile -LogLine "Not all required Variables are set for this Script."
|
||||||
|
|
||||||
} #end if/else
|
} #end if/else
|
||||||
|
|
||||||
|
Write-Logfile -LogLine " "
|
||||||
|
Write-Logfile -LogLine "--------------------------------------------------------------------------------"
|
||||||
|
Write-Logfile -LogLine "Checking for old LogFiles."
|
||||||
|
Write-Logfile -LogLine "--------------------------------------------------------------------------------"
|
||||||
|
|
||||||
|
Remove-Item-withLogging -Path $LogPath -FileKeepTime $LogFileKeepTime -FileBaseName $ScriptName
|
||||||
|
|
||||||
|
Write-Logfile -LogLine " "
|
||||||
|
Write-Logfile -LogLine "********************************************************************************"
|
||||||
|
Write-Logfile -LogLine "Program Completed: $ScriptName on $env:COMPUTERNAME,"
|
||||||
|
Write-Logfile -LogLine "from Account $env:USERDOMAIN\$env:USERNAME."
|
||||||
|
Write-Logfile -LogLine "********************************************************************************"
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
########################################### finishing part ############################################
|
||||||
|
#-----------------------------------------------------------------------------------------------------#
|
||||||
|
|
||||||
|
#Enable only for debugging
|
||||||
|
#exit
|
||||||
|
start-process -w
|
||||||
|
Remove-Variable -Name ScriptName -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ScriptPath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ConfigFile -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ConfigFileContent -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Timestamp1 -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Timestamp2 -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Timestamp3 -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Timestamp4 -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name LogFile -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name LogFileKeepTime -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name LogPath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Module -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name Modules -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ModuleOverrideSourcePath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ModuleDefaultSourcePath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ModuleHKLMRegistryPath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name ModuleHKCURegistryPath -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
Remove-Variable -Name VersionURL -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name DownloadURL -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name InstallPath -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name CurrentFirefoxVersion -Force -ErrorAction SilentlyContinue
|
||||||
|
Remove-Variable -Name NewFirefoxVersion -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
$error.clear()
|
||||||
@ -1,45 +1,140 @@
|
|||||||
|
TITLE DIGITAL DATA - Run all files in directory
|
||||||
@ECHO OFF
|
@ECHO OFF
|
||||||
TITLE DIGITAL DATA - Run all files in directory with current permissions
|
REM ----------------------------------------------------------------------------
|
||||||
ECHO -
|
REM This script runs all specified files in the current directory
|
||||||
ECHO Batch Script
|
REM
|
||||||
ECHO Run all files in directory with current permissions
|
REM Returns: <NOTHING>
|
||||||
ECHO -
|
REM ----------------------------------------------------------------------------
|
||||||
ECHO Digital Data
|
REM Copyright (c) 2024 by Digital Data GmbH
|
||||||
ECHO Ludwig-Rinn-Strasse 16
|
REM
|
||||||
ECHO 35452 Heuchelheim
|
REM Digital Data GmbH • Ludwig-Rinn-Strasse 16 • D-35452 Heuchelheim
|
||||||
ECHO Tel.: 0641 / 202360
|
REM Tel.: 0641/202360 • E-Mail: info-flow@digitaldata.works
|
||||||
ECHO E-Mail: info@didalog.de
|
REM ----------------------------------------------------------------------------
|
||||||
ECHO -
|
REM Creation Date / Author: 13.08.2015 / MK
|
||||||
ECHO Version 1.0.0.0
|
REM Version Date / Editor: 23.11.2024 / MK
|
||||||
ECHO Date: 13.08.2015
|
REM Version Number: 2.0.0.0
|
||||||
ECHO -
|
|
||||||
ECHO Program Startup %date% at %time:~0,8% oclock, on %computername%.
|
|
||||||
|
|
||||||
REM --------------------------------------------------------------
|
REM --------------------------------------------------------------
|
||||||
REM ------------------------set variables-------------------------
|
REM ------------------------set variables-------------------------
|
||||||
REM --------------------------------------------------------------
|
REM --------------------------------------------------------------
|
||||||
|
|
||||||
setlocal enableextensions
|
SET /A ADMINMODE=1
|
||||||
|
SET FILEEXTENSION=*.ps1
|
||||||
|
|
||||||
|
REM -- Choose PowerShell Version --
|
||||||
|
SET POWERSHELLEXE="C:\Program Files\PowerShell\7\pwsh.exe"
|
||||||
|
REM SET POWERSHELLEXE="C:\Program Files\PowerShell\6\pwsh.exe"
|
||||||
|
REM SET POWERSHELLEXE="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
|
||||||
|
REM -------------------------------
|
||||||
|
|
||||||
SET DIRECTORY="%cd%"
|
SET DIRECTORY="%cd%"
|
||||||
SET FILEEXTENSION=*.ps1
|
SET /A COUNT=0
|
||||||
SET COUNT=0
|
SET LOGFILE="%cd%\error.log"
|
||||||
|
|
||||||
REM --------------------------------------------------------------
|
REM --------------------------------------------------------------
|
||||||
REM ---------------------Program 1 / Script 1---------------------
|
REM ------------------------preparing part------------------------
|
||||||
REM --------------------------------------------------------------
|
REM --------------------------------------------------------------
|
||||||
|
|
||||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (ECHO %%f && set /a count+=1)
|
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
|
||||||
ECHO -
|
ECHO Program Startup %date% at %time:~0,8% o'clock, on %computername%.
|
||||||
ECHO Found %count% File(s) with File Extension %FILEEXTENSION% in Directory:
|
|
||||||
ECHO %DIRECTORY%.
|
|
||||||
|
|
||||||
ECHO -
|
ECHO -
|
||||||
ECHO Running this/them now, with your permissions!
|
IF !ADMINMODE! EQU 1 (ECHO WARNING: In AdminMode, network drives will maybe be unavailable! && timeout /T 10)
|
||||||
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (PowerShell.exe -Command "& {Start-Process PowerShell.exe -WindowStyle hidden '-ExecutionPolicy Bypass -File "%%f"'}")
|
|
||||||
|
REM --------------------------------------------------------------
|
||||||
|
REM ---------------------Running Scripts---------------------------
|
||||||
|
REM --------------------------------------------------------------
|
||||||
|
|
||||||
|
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (
|
||||||
|
ECHO %%f
|
||||||
|
SET /a COUNT+=1
|
||||||
|
)
|
||||||
|
ECHO -
|
||||||
|
ECHO Found %COUNT% File(s) with File Extension %FILEEXTENSION% in Directory:
|
||||||
|
ECHO %DIRECTORY%
|
||||||
|
|
||||||
ECHO -
|
ECHO -
|
||||||
|
IF EXIST "!POWERSHELLEXE!" (
|
||||||
|
ECHO Running these scripts now:
|
||||||
|
FOR /F "tokens=*" %%f in ('dir /S /b %FILEEXTENSION%') do (
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "SCRIPT=%%f"
|
||||||
|
ECHO Running script:
|
||||||
|
ECHO !SCRIPT!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "ARGUMENTS=-NoProfile -ExecutionPolicy Bypass -File \""!SCRIPT!\"""
|
||||||
|
ECHO With Arguments:
|
||||||
|
ECHO !ARGUMENTS!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "SUBCOMMAND=Start-Process -FilePath '!POWERSHELLEXE!' -WindowStyle hidden -ArgumentList '!ARGUMENTS!' "
|
||||||
|
ECHO Subcommand:
|
||||||
|
ECHO !SUBCOMMAND!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
IF !ADMINMODE! EQU 1 (
|
||||||
|
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden -Verb runas {!SUBCOMMAND!} "
|
||||||
|
) ELSE (
|
||||||
|
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden {!SUBCOMMAND!} "
|
||||||
|
)
|
||||||
|
ECHO In nested command:
|
||||||
|
ECHO !COMMAND!
|
||||||
|
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "!COMMAND!"
|
||||||
|
|
||||||
|
IF ERRORLEVEL 1 (
|
||||||
|
ECHO There was an error running the script: !SCRIPT! >> !LOGFILE!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) ELSE (
|
||||||
|
ECHO WARNING specified POWERSHELLEXE-Path does not exist or access denied!
|
||||||
|
ECHO Falling back to build in Powershell Version.
|
||||||
|
timeout /T 30
|
||||||
|
|
||||||
|
ECHO Running these scripts now:
|
||||||
|
FOR /F "tokens=*" %%f in ('dir /b %FILEEXTENSION%') do (
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "SCRIPT=%%f"
|
||||||
|
ECHO Running script:
|
||||||
|
ECHO !SCRIPT!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "ARGUMENTS=-NoProfile -ExecutionPolicy Bypass -File \""!SCRIPT!\"""
|
||||||
|
ECHO With Arguments:
|
||||||
|
ECHO !ARGUMENTS!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
SET "SUBCOMMAND=Start-Process -FilePath 'powershell.exe' -WindowStyle hidden -ArgumentList '!ARGUMENTS!' "
|
||||||
|
ECHO Subcommand:
|
||||||
|
ECHO !SUBCOMMAND!
|
||||||
|
|
||||||
|
ECHO -
|
||||||
|
IF !ADMINMODE! EQU 1 (
|
||||||
|
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden -Verb runas {!SUBCOMMAND!} "
|
||||||
|
) ELSE (
|
||||||
|
SET "COMMAND=Start-Process powershell.exe -WindowStyle hidden {!SUBCOMMAND!} "
|
||||||
|
)
|
||||||
|
ECHO In nested command:
|
||||||
|
ECHO !COMMAND!
|
||||||
|
|
||||||
|
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "!COMMAND!"
|
||||||
|
|
||||||
|
IF ERRORLEVEL 1 (
|
||||||
|
ECHO There was an error running the script: !SCRIPT! >> !LOGFILE!
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
REM --------------------------------------------------------------
|
||||||
|
REM -------------------------final part---------------------------
|
||||||
|
REM --------------------------------------------------------------
|
||||||
|
|
||||||
|
ENDLOCAL
|
||||||
|
ECHO -
|
||||||
|
ECHO Program Complete %date% at %time:~0,8% o'clock, on %computername%.
|
||||||
ECHO This Window will close in:
|
ECHO This Window will close in:
|
||||||
#timeout /T 10
|
timeout /T 10
|
||||||
endlocal
|
|
||||||
exit
|
exit
|
||||||
@ -1,6 +1,14 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Version 1.1.0.0 - 23.11.2024
|
||||||
|
NEW: - Logging and Configfile implemented
|
||||||
|
FIX: -
|
||||||
|
CHG: - New way to retrive the new software version (now via JSON)
|
||||||
|
REM: -
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
Version 1.0.0.0 - 04.11.2024
|
Version 1.0.0.0 - 04.11.2024
|
||||||
NEW: -
|
NEW: -
|
||||||
FIX: -
|
FIX: -
|
||||||
|
|||||||
47
current/Update-Firefox/Update-Firefox_Settings.ini
Normal file
47
current/Update-Firefox/Update-Firefox_Settings.ini
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
####################################################################################################
|
||||||
|
# Digital Data Configuration File (Template Date: 30.07.2016) #
|
||||||
|
# UTF-8 Coding required! #
|
||||||
|
# incl. FailSafe functions that are active when information is missing. #
|
||||||
|
####################################################################################################
|
||||||
|
|
||||||
|
#==================================================================================================#
|
||||||
|
########################################## General Setup ###########################################
|
||||||
|
#==================================================================================================#
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# Path in which the log files will be stored. #
|
||||||
|
# Example: E:\LogFiles\<ScriptName> #
|
||||||
|
# FailSafe Setting is: <ScriptPath>\Logs #
|
||||||
|
####################################################################################################
|
||||||
|
LogPath =
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# Numerical value how long (in days) log files will be kept. ValidateRange is 0 - 1000 #
|
||||||
|
# Setting the Value to 0 disables this Function. #
|
||||||
|
# FailSafe Setting is: 60 #
|
||||||
|
####################################################################################################
|
||||||
|
LogFileKeepTime = 30
|
||||||
|
|
||||||
|
#==================================================================================================#
|
||||||
|
########################################## Profile Setup ###########################################
|
||||||
|
#==================================================================================================#
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# VersionURL #
|
||||||
|
# Set the URL with the info about current version distibution. #
|
||||||
|
# Result file should be JSON #
|
||||||
|
####################################################################################################
|
||||||
|
VersionURL = https://product-details.mozilla.org/1.0/firefox_versions.json
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# DownloadURL #
|
||||||
|
# Set the URL where to download the new software version. #
|
||||||
|
# Use "%NewFirefoxVersion%" as placeholder for the new version number, got from the VersionURL. #
|
||||||
|
####################################################################################################
|
||||||
|
DownloadURL = https://download-installer.cdn.mozilla.net/pub/firefox/releases/%NewFirefoxVersion%/win64/de/Firefox%20Setup%20%NewFirefoxVersion%.msi
|
||||||
|
|
||||||
|
####################################################################################################
|
||||||
|
# InstallPath #
|
||||||
|
# Set the local installation path. #
|
||||||
|
####################################################################################################
|
||||||
|
InstallPath = D:\ProgramFiles\Mozilla Firefox
|
||||||
Loading…
x
Reference in New Issue
Block a user