17
17
. NOTES
18
18
Author: Olav Rønnestad Birkeland | github.com/o-l-a-v
19
19
Created: 2019-03-10
20
- Modified: 2024-12-27
20
+ Modified: 2025-01-13
21
21
22
22
. EXAMPLE
23
23
# Run from PowerShell ISE or Visual Studio Code, user context
34
34
35
35
# Input parameters and expected output
36
36
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingComputerNameHardcoded' , ' ' , Justification = ' There are no secret hostnames exposed in this script.' )]
37
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSReviewUnusedParameter' , ' AcceptLicenses' , Justification = ' False positive.' )]
37
38
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSReviewUnusedParameter' , ' SkipAuthenticodeCheck' , Justification = ' False positive.' )]
38
39
[OutputType ([System.Void ])]
39
40
Param (
@@ -231,15 +232,11 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
231
232
232
233
. NOTES
233
234
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
236
237
237
238
. EXAMPLE
238
239
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
243
240
#>
244
241
245
242
# Input parameters and expected output
@@ -299,10 +296,10 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
299
296
$VersionFilter = [string ](
300
297
$ (
301
298
if ($IncludePrerelease .' IsPresent' ) {
302
- ' IsAbsoluteLatestVersion'
299
+ ' IsAbsoluteLatestVersion eq true '
303
300
}
304
301
else {
305
- ' IsLatestVersion and not IsPrerelease'
302
+ ' IsLatestVersion eq true and IsPrerelease eq false '
306
303
}
307
304
)
308
305
)
@@ -420,6 +417,16 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
420
417
$Results.Where {
421
418
-not [string ]::IsNullOrEmpty($_ .' Id' )
422
419
}.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
+ )
423
430
[PSCustomObject ]@ {
424
431
' Name' = [string ] $_ .' title' .' #text'
425
432
' Author' = [string ] $_ .' author' .' name'
@@ -437,15 +444,21 @@ function Find-PSGalleryPackageLatestVersionUsingApiInBatch {
437
444
' Owners' = [string ] $_ .' properties' .' owners'
438
445
' PublishedDate' = [nullable [datetime ]] $_ .' properties' .' Published' .' #text'
439
446
' 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
+ )
449
462
' Unlisted' = [bool ]$ (
450
463
[string ]::IsNullOrEmpty($_ .' properties' .' Published' .' #text' ) -or
451
464
$ ([datetime ]($_ .' properties' .' Published' .' #text' )).' Year' -le 1900
@@ -486,7 +499,7 @@ function Save-PSResourceInParallel {
486
499
. NOTES
487
500
Author: Olav Rønnestad Birkeland | github.com/o-l-a-v
488
501
Created: 2023-11-16
489
- Modified: 2024-12-27
502
+ Modified: 2024-01-13
490
503
491
504
. EXAMPLE
492
505
# All Az modules
@@ -531,6 +544,9 @@ function Save-PSResourceInParallel {
531
544
[Parameter (HelpMessage = ' A hashtable that specifies resources to install.' , ParameterSetName = ' RequiredResourceFileParameterSet' )]
532
545
[hashtable ] $RequiredResource ,
533
546
547
+ [Parameter (HelpMessage = ' Whether to accept licenses for packages that requires it, defaults to false.' )]
548
+ [bool ] $AcceptLicense ,
549
+
534
550
[Parameter (HelpMessage = ' Check validation for signed and catalog files.' )]
535
551
[bool ] $AuthenticodeCheck = $false ,
536
552
@@ -573,6 +589,9 @@ function Save-PSResourceInParallel {
573
589
[ValidateNotNullOrEmpty ()]
574
590
[string ] $Repository ,
575
591
592
+ [Parameter ()]
593
+ [bool ] $AcceptLicense = $false ,
594
+
576
595
[Parameter ()]
577
596
[bool ] $AuthenticodeCheck = $false ,
578
597
@@ -590,7 +609,9 @@ function Save-PSResourceInParallel {
590
609
)
591
610
$ErrorActionPreference = ' Stop'
592
611
$null = Import-Module - Name $PSResourceGetPath
612
+ # Create splat variable based on input
593
613
$Splat = [ordered ]@ {
614
+ ' AcceptLicense' = [bool ] $AcceptLicense
594
615
' AuthenticodeCheck' = [bool ] $AuthenticodeCheck
595
616
' IncludeXml' = [bool ] $IncludeXml
596
617
' Name' = [string ] $Name
@@ -607,7 +628,21 @@ function Save-PSResourceInParallel {
607
628
if ($PSBoundParameters.ContainsKey (' TemporaryPath' )) {
608
629
$Splat .' TemporaryPath' = [string ] $TemporaryPath
609
630
}
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
+ }
611
646
}
612
647
613
648
# Initilize runspace pool
@@ -624,6 +659,7 @@ function Save-PSResourceInParallel {
624
659
if ($PSCmdlet .' ParameterSetName' -eq ' NameParameterSet' ) {
625
660
foreach ($ModuleName in $Name ) {
626
661
$Splat = [ordered ]@ {
662
+ ' AcceptLicense' = [bool ] $AcceptLicense
627
663
' AuthenticodeCheck' = [bool ] $AuthenticodeCheck
628
664
' IncludeXml' = [bool ] $IncludeXml
629
665
' Name' = [string ] $ModuleName
@@ -647,6 +683,7 @@ function Save-PSResourceInParallel {
647
683
# From $RequiredResource
648
684
' Name' = [string ] $_
649
685
# Not from $RequiredResource
686
+ ' AcceptLicense' = [bool ] $AcceptLicense
650
687
' AuthenticodeCheck' = [bool ] $AuthenticodeCheck
651
688
' IncludeXml' = [bool ] $IncludeXml
652
689
' Path' = [string ] $Path
@@ -672,6 +709,7 @@ function Save-PSResourceInParallel {
672
709
# From $InputObject
673
710
' Name' = [string ] $_ .' Name'
674
711
# Not from $RequiredResource
712
+ ' AcceptLicense' = [bool ] $AcceptLicense
675
713
' AuthenticodeCheck' = [bool ] $AuthenticodeCheck
676
714
' IncludeXml' = [bool ] $IncludeXml
677
715
' Path' = [string ] $Path
@@ -981,6 +1019,7 @@ function Update-ModulesInstalled {
981
1019
Write-Information - MessageData (' Updating {0} outdated modules in parallel.' -f $ModulesInstalledWithNewerVersionAvailable .' Count' .ToString())
982
1020
}
983
1021
$Splat = [ordered ]@ {
1022
+ ' AcceptLicense' = [bool ]($AcceptLicenses )
984
1023
' AuthenticodeCheck' = [bool ](-not $SkipAuthenticodeCheck )
985
1024
' IncludeXml' = [bool ] $true
986
1025
' Name' = [string []] $ModulesInstalledWithNewerVersionAvailable .' Name'
@@ -1112,6 +1151,7 @@ function Install-ModulesMissing {
1112
1151
1113
1152
# Install missing modules
1114
1153
$Splat = [ordered ]@ {
1154
+ ' AcceptLicense' = [bool ]($AcceptLicenses )
1115
1155
' AuthenticodeCheck' = [bool ](-not $SkipAuthenticodeCheck )
1116
1156
' IncludeXml' = [bool ] $true
1117
1157
' Name' = [string []] $ModulesMissingPsgInfo .' Name'
@@ -1268,6 +1308,7 @@ function Install-SubModulesMissing {
1268
1308
Write-Information - MessageData (' Installing {0} missing submodules in parallel.' -f $SubModulesMissing .' Count' .ToString())
1269
1309
}
1270
1310
$Splat = [ordered ]@ {
1311
+ ' AcceptLicense' = [bool ]($AcceptLicenses )
1271
1312
' AuthenticodeCheck' = [bool ](-not $SkipAuthenticodeCheck )
1272
1313
' IncludeXml' = [bool ] $true
1273
1314
' Name' = [string []] $SubModulesMissing .' Name'
@@ -2023,7 +2064,7 @@ function Get-Summary {
2023
2064
# Check if any got any objects
2024
2065
if (
2025
2066
$Script :StatisticsVariables.ForEach {
2026
- Get-Variable - Name $_ .' VariableName' - Scope ' Script' - ValueOnly - ErrorAction ' SilentlyContinue '
2067
+ Get-Variable - Name $_ .' VariableName' - Scope ' Script' - ValueOnly - ErrorAction ' Ignore '
2027
2068
}.Where{
2028
2069
-not [string ]::IsNullOrEmpty($_ )
2029
2070
}.' Count' -le 0
0 commit comments