@@ -89,6 +89,10 @@ function Publish-Module {
8989 )
9090
9191 Begin {
92+ # Change security protocol to TLS 1.2
93+ $script :securityProtocol = [Net.ServicePointManager ]::SecurityProtocol
94+ [Net.ServicePointManager ]::SecurityProtocol = [Net.SecurityProtocolType ]::Tls12
95+
9296 if ($LicenseUri -and -not (Test-WebUri - uri $LicenseUri )) {
9397 $message = $LocalizedData.InvalidWebUri -f ($LicenseUri , " LicenseUri" )
9498 ThrowError - ExceptionName " System.ArgumentException" `
@@ -214,7 +218,7 @@ function Publish-Module {
214218
215219 # Find the module to be published locally, search by name and RequiredVersion
216220 $module = Microsoft.PowerShell.Core\Get-Module - ListAvailable - Name $Name - Verbose:$false |
217- Microsoft.PowerShell.Core\Where-Object {
221+ Microsoft.PowerShell.Core\Where-Object {
218222 $modInfoPrerelease = $null
219223 if ($_.PrivateData -and
220224 $_.PrivateData.GetType ().ToString() -eq " System.Collections.Hashtable" -and
@@ -377,7 +381,7 @@ function Publish-Module {
377381 # Copy-Item -Recurse -Force includes hidden items like .git directories, which we don't want
378382 # This finds all the items without force (leaving out hidden files and dirs) then copies them
379383 Microsoft.PowerShell.Management\Get-ChildItem $Path - recurse |
380- Microsoft.PowerShell.Management\Copy-Item - Force - Confirm:$false - WhatIf:$false - Destination {
384+ Microsoft.PowerShell.Management\Copy-Item - Force - Confirm:$false - WhatIf:$false - Destination {
381385 if ($_.PSIsContainer ) {
382386 Join-Path $tempModulePathForFormatVersion $_.Parent.FullName.substring ($path.length )
383387 }
@@ -458,8 +462,8 @@ function Publish-Module {
458462 # Check if the specified module name is already used for a script on the specified repository
459463 # Use Find-Script to check if that name is already used as scriptname
460464 $scriptPSGetItemInfo = Find-Script @FindParameters |
461- Microsoft.PowerShell.Core\Where-Object {$_.Name -eq $moduleName } |
462- Microsoft.PowerShell.Utility\Select-Object - Last 1 - ErrorAction Ignore
465+ Microsoft.PowerShell.Core\Where-Object { $_.Name -eq $moduleName } |
466+ Microsoft.PowerShell.Utility\Select-Object - Last 1 - ErrorAction Ignore
463467 if ($scriptPSGetItemInfo ) {
464468 $message = $LocalizedData.SpecifiedNameIsAlearyUsed -f ($moduleName , $Repository , ' Find-Script' )
465469 ThrowError - ExceptionName " System.InvalidOperationException" `
@@ -472,8 +476,8 @@ function Publish-Module {
472476
473477 $null = $FindParameters.Remove (' Tag' )
474478 $currentPSGetItemInfo = Find-Module @FindParameters |
475- Microsoft.PowerShell.Core\Where-Object {$_.Name -eq $moduleInfo.Name } |
476- Microsoft.PowerShell.Utility\Select-Object - Last 1 - ErrorAction Ignore
479+ Microsoft.PowerShell.Core\Where-Object { $_.Name -eq $moduleInfo.Name } |
480+ Microsoft.PowerShell.Utility\Select-Object - Last 1 - ErrorAction Ignore
477481
478482 if ($currentPSGetItemInfo ) {
479483 $result = ValidateAndGet- VersionPrereleaseStrings - Version $currentPSGetItemInfo.Version - CallerPSCmdlet $PSCmdlet
@@ -580,4 +584,9 @@ function Publish-Module {
580584 Microsoft.PowerShell.Management\Remove-Item $tempModulePath - Force - Recurse - ErrorAction Ignore - WarningAction SilentlyContinue - Confirm:$false - WhatIf:$false
581585 }
582586 }
587+
588+ End {
589+ # Change back to user specified security protocol
590+ [Net.ServicePointManager ]::SecurityProtocol = $script :securityProtocol
591+ }
583592}
0 commit comments