Skip to content

Commit 417661f

Browse files
committedJan 15, 2025·
Update script
1 parent 70d8f7e commit 417661f

File tree

2 files changed

+83
-21
lines changed

2 files changed

+83
-21
lines changed
 

‎PowerShellModulesUpdater/CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
* Changelog format follows [Keep a Changelog](https://keepachangelog.com/en).
66
* Versioning adheres to [Semantic Versioning](https://semver.org/).
77

8+
## 1.21.0 - 2025-01-13
9+
10+
### Added
11+
12+
* Function `Save-PSResourceInParallel`:
13+
* `-AcceptLicenses` input parameter finally works again.
14+
* `Microsoft.PowerShell.PSResourceGet` v1.1.0 was released with `-AcceptLicense` finally added to `Save-PSResource`.
15+
* Retry `Save-PSResource` if DNS fails to resolve. Both for added resiliency, but also to work around the Edgio bankruptcy / `*.azureedge.net` CDN retirement, where DNS sometimes fail to resolve due to errors in DNS propagation.
16+
* 2025-01-03: <https://github.com/PowerShell/PowerShell/discussions/24734>
17+
* 2025-01-13: <https://github.com/PowerShell/PowerShellGallery/issues/297>
18+
19+
### Fixed
20+
21+
* Function `Find-PSGalleryPackageLatestVersionUsingApiInBatch`:
22+
* Workaround for PowerShell Gallery API bug where `$select=Tags` does not return tags for some modules, like `Trackyon.Utils`.
23+
* 2025-01-13: <https://github.com/PowerShell/PowerShellGallery/issues/298>
24+
* Use `IsLatestVersion eq true` instead of unary comparison `IsLatestVersion` due to PowerShell Gallery API bug.
25+
* 2024-05-15: <https://github.com/PowerShell/PowerShellGallery/issues/273>
26+
* Fix in PSResourceGet: <https://github.com/PowerShell/PSResourceGet/pull/1761>
27+
* Use `-ErrorAction Ignore` instead of `SilentlyContinue` when `Get-Variable` on a variable that might not exist yet to not add the error to the `$Error` variable.
28+
829
## 1.20.2 - 2024-12-27
930

1031
### Fixed

‎PowerShellModulesUpdater/PowerShellModulesUpdater.ps1

+62-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.NOTES
1818
Author: Olav Rønnestad Birkeland | github.com/o-l-a-v
1919
Created: 2019-03-10
20-
Modified: 2024-12-27
20+
Modified: 2025-01-13
2121
2222
.EXAMPLE
2323
# Run from PowerShell ISE or Visual Studio Code, user context
@@ -34,6 +34,7 @@
3434

3535
# Input parameters and expected output
3636
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingComputerNameHardcoded', '', Justification = 'There are no secret hostnames exposed in this script.')]
37+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'AcceptLicenses', Justification = 'False positive.')]
3738
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'SkipAuthenticodeCheck', Justification = 'False positive.')]
3839
[OutputType([System.Void])]
3940
Param (
@@ -231,15 +232,11 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
231232
232233
.NOTES
233234
Author: Olav Rønnestad Birkeland | github.com/o-l-a-v
234-
Created: 240313
235-
Modified: 240330
235+
Created: 2024-03-13
236+
Modified: 2025-01-13
236237
237238
.EXAMPLE
238239
Find-PSGalleryPackageLatestVersionUsingApiInBatch -PackageIds 'Az.Accounts','Az.Resources' -Verbose
239-
Find-PSGalleryPackageLatestVersionUsingApiInBatch -PackageIds 'Az.CosmosDB' -IncludePrerelease -Verbose -As
240-
Find-PSGalleryPackageLatestVersionUsingApiInBatch -PackageIds 'Az.*' -MinimalInfo -Verbose
241-
Find-PSGalleryPackageLatestVersionUsingApiInBatch -PackageIds 'Az.*' -AsHashtable -Verbose
242-
Find-PSGalleryPackageLatestVersionUsingApiInBatch -PackageIds 'Az.*' -AsHashtable -MinimalInfo -Verbose
243240
#>
244241

245242
# Input parameters and expected output
@@ -299,10 +296,10 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
299296
$VersionFilter = [string](
300297
$(
301298
if ($IncludePrerelease.'IsPresent') {
302-
'IsAbsoluteLatestVersion'
299+
'IsAbsoluteLatestVersion eq true'
303300
}
304301
else {
305-
'IsLatestVersion and not IsPrerelease'
302+
'IsLatestVersion eq true and IsPrerelease eq false'
306303
}
307304
)
308305
)
@@ -420,6 +417,16 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
420417
$Results.Where{
421418
-not [string]::IsNullOrEmpty($_.'Id')
422419
}.ForEach{
420+
$Tags = [string[]](
421+
$(
422+
if ($_.'properties'.'Tags' -is [System.Xml.XmlLinkedNode]) {
423+
$_.'properties'.'Tags'.'#text'
424+
}
425+
else {
426+
$_.'properties'.'Tags'
427+
}
428+
).Split(' ', [StringSplitOptions]::RemoveEmptyEntries) | Sort-Object -Unique
429+
)
423430
[PSCustomObject]@{
424431
'Name' = [string] $_.'title'.'#text'
425432
'Author' = [string] $_.'author'.'name'
@@ -437,15 +444,21 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
437444
'Owners' = [string] $_.'properties'.'owners'
438445
'PublishedDate' = [nullable[datetime]] $_.'properties'.'Published'.'#text'
439446
'RequireLicenseAcceptance' = [bool]($_.'properties'.'RequireLicenseAcceptance'.'#text' -eq 'true')
440-
'Tags' = [string[]](
441-
$(
442-
if ($_.'properties'.'Tags' -is [System.Xml.XmlLinkedNode]) {
443-
$_.'properties'.'Tags'.'#text'
444-
}
445-
else {
446-
$_.'properties'.'Tags'
447-
}
448-
).Split(' ', [StringSplitOptions]::RemoveEmptyEntries) | Sort-Object -Unique)
447+
'Tags' = [string[]] $Tags
448+
'Type' = [string]$(
449+
if ([string]::IsNullOrWhiteSpace($Tags)) {
450+
'Unknown'
451+
}
452+
elseif ($Tags.Contains('PSModule')) {
453+
'Module'
454+
}
455+
elseif ($Tags.Contains('PSScript')) {
456+
'Script'
457+
}
458+
else {
459+
'Unknown'
460+
}
461+
)
449462
'Unlisted' = [bool]$(
450463
[string]::IsNullOrEmpty($_.'properties'.'Published'.'#text') -or
451464
$([datetime]($_.'properties'.'Published'.'#text')).'Year' -le 1900
@@ -486,7 +499,7 @@ function Save-PSResourceInParallel {
486499
.NOTES
487500
Author: Olav Rønnestad Birkeland | github.com/o-l-a-v
488501
Created: 2023-11-16
489-
Modified: 2024-12-27
502+
Modified: 2024-01-13
490503
491504
.EXAMPLE
492505
# All Az modules
@@ -531,6 +544,9 @@ function Save-PSResourceInParallel {
531544
[Parameter(HelpMessage = 'A hashtable that specifies resources to install.', ParameterSetName = 'RequiredResourceFileParameterSet')]
532545
[hashtable] $RequiredResource,
533546

547+
[Parameter(HelpMessage = 'Whether to accept licenses for packages that requires it, defaults to false.')]
548+
[bool] $AcceptLicense,
549+
534550
[Parameter(HelpMessage = 'Check validation for signed and catalog files.')]
535551
[bool] $AuthenticodeCheck = $false,
536552

@@ -573,6 +589,9 @@ function Save-PSResourceInParallel {
573589
[ValidateNotNullOrEmpty()]
574590
[string] $Repository,
575591

592+
[Parameter()]
593+
[bool] $AcceptLicense = $false,
594+
576595
[Parameter()]
577596
[bool] $AuthenticodeCheck = $false,
578597

@@ -590,7 +609,9 @@ function Save-PSResourceInParallel {
590609
)
591610
$ErrorActionPreference = 'Stop'
592611
$null = Import-Module -Name $PSResourceGetPath
612+
# Create splat variable based on input
593613
$Splat = [ordered]@{
614+
'AcceptLicense' = [bool] $AcceptLicense
594615
'AuthenticodeCheck' = [bool] $AuthenticodeCheck
595616
'IncludeXml' = [bool] $IncludeXml
596617
'Name' = [string] $Name
@@ -607,7 +628,21 @@ function Save-PSResourceInParallel {
607628
if ($PSBoundParameters.ContainsKey('TemporaryPath')) {
608629
$Splat.'TemporaryPath' = [string] $TemporaryPath
609630
}
610-
Microsoft.PowerShell.PSResourceGet\Save-PSResource @Splat
631+
# Retry if DNS fails to resolve
632+
Try {
633+
Microsoft.PowerShell.PSResourceGet\Save-PSResource @Splat
634+
}
635+
Catch {
636+
if (
637+
-not [string]::IsNullOrWhiteSpace($_.'ErrorRecord'.'Exception'.'Message') -and
638+
$_.'ErrorRecord'.'Exception'.'Message'.Contains('No such host is known.')
639+
) {
640+
Microsoft.PowerShell.PSResourceGet\Save-PSResource @Splat
641+
}
642+
else {
643+
throw $_
644+
}
645+
}
611646
}
612647

613648
# Initilize runspace pool
@@ -624,6 +659,7 @@ function Save-PSResourceInParallel {
624659
if ($PSCmdlet.'ParameterSetName' -eq 'NameParameterSet') {
625660
foreach ($ModuleName in $Name) {
626661
$Splat = [ordered]@{
662+
'AcceptLicense' = [bool] $AcceptLicense
627663
'AuthenticodeCheck' = [bool] $AuthenticodeCheck
628664
'IncludeXml' = [bool] $IncludeXml
629665
'Name' = [string] $ModuleName
@@ -647,6 +683,7 @@ function Save-PSResourceInParallel {
647683
# From $RequiredResource
648684
'Name' = [string] $_
649685
# Not from $RequiredResource
686+
'AcceptLicense' = [bool] $AcceptLicense
650687
'AuthenticodeCheck' = [bool] $AuthenticodeCheck
651688
'IncludeXml' = [bool] $IncludeXml
652689
'Path' = [string] $Path
@@ -672,6 +709,7 @@ function Save-PSResourceInParallel {
672709
# From $InputObject
673710
'Name' = [string] $_.'Name'
674711
# Not from $RequiredResource
712+
'AcceptLicense' = [bool] $AcceptLicense
675713
'AuthenticodeCheck' = [bool] $AuthenticodeCheck
676714
'IncludeXml' = [bool] $IncludeXml
677715
'Path' = [string] $Path
@@ -981,6 +1019,7 @@ function Update-ModulesInstalled {
9811019
Write-Information -MessageData ('Updating {0} outdated modules in parallel.' -f $ModulesInstalledWithNewerVersionAvailable.'Count'.ToString())
9821020
}
9831021
$Splat = [ordered]@{
1022+
'AcceptLicense' = [bool]($AcceptLicenses)
9841023
'AuthenticodeCheck' = [bool](-not $SkipAuthenticodeCheck)
9851024
'IncludeXml' = [bool] $true
9861025
'Name' = [string[]] $ModulesInstalledWithNewerVersionAvailable.'Name'
@@ -1112,6 +1151,7 @@ function Install-ModulesMissing {
11121151

11131152
# Install missing modules
11141153
$Splat = [ordered]@{
1154+
'AcceptLicense' = [bool]($AcceptLicenses)
11151155
'AuthenticodeCheck' = [bool](-not $SkipAuthenticodeCheck)
11161156
'IncludeXml' = [bool] $true
11171157
'Name' = [string[]] $ModulesMissingPsgInfo.'Name'
@@ -1268,6 +1308,7 @@ function Install-SubModulesMissing {
12681308
Write-Information -MessageData ('Installing {0} missing submodules in parallel.' -f $SubModulesMissing.'Count'.ToString())
12691309
}
12701310
$Splat = [ordered]@{
1311+
'AcceptLicense' = [bool]($AcceptLicenses)
12711312
'AuthenticodeCheck' = [bool](-not $SkipAuthenticodeCheck)
12721313
'IncludeXml' = [bool] $true
12731314
'Name' = [string[]] $SubModulesMissing.'Name'
@@ -2023,7 +2064,7 @@ function Get-Summary {
20232064
# Check if any got any objects
20242065
if (
20252066
$Script:StatisticsVariables.ForEach{
2026-
Get-Variable -Name $_.'VariableName' -Scope 'Script' -ValueOnly -ErrorAction 'SilentlyContinue'
2067+
Get-Variable -Name $_.'VariableName' -Scope 'Script' -ValueOnly -ErrorAction 'Ignore'
20272068
}.Where{
20282069
-not [string]::IsNullOrEmpty($_)
20292070
}.'Count' -le 0

0 commit comments

Comments
 (0)
Please sign in to comment.