From 301dd14ff674d7554b2bec8d9f37bb23536e0532 Mon Sep 17 00:00:00 2001 From: Frank Weggelaar Date: Wed, 31 Jul 2024 11:44:09 +0200 Subject: [PATCH] Initial script --- VMSCertRoller.ps1 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 VMSCertRoller.ps1 diff --git a/VMSCertRoller.ps1 b/VMSCertRoller.ps1 new file mode 100644 index 0000000..ba266bd --- /dev/null +++ b/VMSCertRoller.ps1 @@ -0,0 +1,32 @@ +$thumbprint = "eb71fa074ffe22be64caac5893b457de3bc311ab" #New certificate thumbprint + +Write-Host 'Setting SecurityProtocol to TLS 1.2 and greater' -ForegroundColor Green +$protocol = [Net.SecurityProtocolType]::SystemDefault +[enum]::GetNames([Net.SecurityProtocolType]) | Where-Object { + # Match any TLS version greater than 1.1 + ($_ -match 'Tls(\d)(\d+)?') -and ([version]("$($Matches[1]).$([int]$Matches[2])")) -gt 1.1 +} | Foreach-Object { $protocol = $protocol -bor [Net.SecurityProtocolType]::$_ } +[Net.ServicePointManager]::SecurityProtocol = $protocol + +if ($null -eq (Get-PackageSource -Name NuGet -ErrorAction Ignore)) { + Write-Host 'Registering NuGet package source' -ForegroundColor Green + $null = Register-PackageSource -Name NuGet -Location https://www.nuget.org/api/v2 -ProviderName NuGet -Trusted -Force +} + +$nugetProvider = Get-PackageProvider -Name NuGet -ErrorAction Ignore +$requiredVersion = [Microsoft.PackageManagement.Internal.Utility.Versions.FourPartVersion]::Parse('2.8.5.201') +if ($null -eq $nugetProvider -or $nugetProvider.Version -lt $requiredVersion) { + Write-Host 'Installing NuGet package provider' -ForegroundColor Green + $null = Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force +} + +if ($null -eq (Get-Module -ListAvailable PowerShellGet | Where-Object Version -ge 2.2.5)) { + Write-Host 'Installing PowerShellGet 2.2.5 or greater' -ForegroundColor Green + $null = Install-Module PowerShellGet -MinimumVersion 2.2.5 -Scope CurrentUser -AllowClobber -Force -ErrorAction Stop +} + +Write-Host 'Installing MilestonePSTools' -ForegroundColor Green +Install-Module MilestonePSTools -Scope AllUsers -Force -ErrorAction Stop -SkipPublisherCheck -AllowClobber + +Set-VmsModuleConfig -EnableTelemetry $false +Set-XProtectCertificate -VmsComponent MobileServer -Thumbprint $thumbprint -RemoveOldCert -Force \ No newline at end of file