@@ -125,6 +125,24 @@ function New-UpliftDSCConfigurationData {
125
125
}
126
126
}
127
127
128
+ function Get-UpliftDscConfigurationStatus () {
129
+ $status = Get-DscConfigurationStatus
130
+
131
+
132
+ Write-UpliftInfoMessage " ResourcesInDesiredState"
133
+ foreach ($resource in $status.ResourcesInDesiredState ) {
134
+ Write-UpliftInfoMessage " [+] $ ( $resource.ResourceId ) "
135
+ }
136
+
137
+ Write-UpliftInfoMessage " "
138
+
139
+ Write-UpliftInfoMessage " ResourcesNotInDesiredState"
140
+ foreach ($resource in $status.ResourcesNotInDesiredState ) {
141
+ Write-UpliftInfoMessage " [!] $ ( $resource.ResourceId ) "
142
+ Write-UpliftInfoMessage $resource.Error
143
+ }
144
+ }
145
+
128
146
function Start-UpliftDSCConfiguration {
129
147
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Scope= " Function" )]
130
148
[Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSUseShouldProcessForStateChangingFunctions" , " " , Scope= " Function" )]
@@ -216,10 +234,14 @@ function Start-UpliftDSCConfiguration {
216
234
}
217
235
}
218
236
237
+ Get-UpliftDscConfigurationStatus
238
+
219
239
throw $message
220
240
} else {
221
241
$message = " [+] DSC: $Name is in a desired state"
222
242
Write-UpliftMessage $message
243
+
244
+ Get-UpliftDscConfigurationStatus
223
245
}
224
246
} else {
225
247
Write-UpliftMessage " [+] No check for DSC [$Name ] is done. Skipping."
@@ -494,60 +516,84 @@ function Find-UpliftFileInPath {
494
516
return $exeFile.FullName
495
517
}
496
518
497
- function Install-UpliftPSModules {
519
+ function Install-UpliftPSModule {
498
520
499
521
Param (
500
- [ Parameter ( Mandatory = $True )]
501
- $packages
522
+ $name ,
523
+ $version
502
524
)
503
525
504
- foreach ($package in $packages ) {
526
+ $maxAttempt = 5
527
+ $attempt = 1
528
+ $success = $false
505
529
506
- $maxAttempt = 5
507
- $attempt = 0
508
- $success = $false
530
+ while ( ($attempt -le $maxAttempt ) -and (-not $success ) ) {
509
531
510
- $name = $package [" Id" ]
511
- $version = $package [" Version" ]
512
-
513
- while ( ($attempt -le $maxAttempt ) -and (-not $success ) ) {
514
-
515
- try {
516
- Write-UpliftMessage " `t [$attempt /$maxAttempt ] installing package: $name $version "
532
+ try {
533
+ Write-UpliftMessage " `t [$attempt /$maxAttempt ] ensuring package: $name $version "
534
+ $existinModule = $null
517
535
518
- Write-UpliftMessage " `t checking is package exists: $name $version "
519
- $existingModule = Get-Module - ListAvailable - Name $name
536
+ if ( [String ]::IsNullOrEmpty($version ) -eq $True ) {
537
+ Write-UpliftMessage " `t checking if package exists: $name $version "
538
+ $existinModule = Get-Module - ListAvailable | Where-Object { $_.Name -eq $name }
539
+ } else {
540
+ Write-UpliftMessage " `t checking if package exists: $name $version "
541
+ $existinModule = Get-Module - ListAvailable | Where-Object { $_.Name -eq $name -and $_.Version -eq $version }
542
+ }
520
543
521
- if ( $existingModule ) {
522
- Write-UpliftMessage " `t`t package exists, nothing to do: $name $version "
523
- }
524
- else {
525
- Write-UpliftMessage " `t`t package does not exist, installing: $name $version "
544
+ if ( $null -ne $existinModule ) {
545
+ Write-UpliftMessage " `t`t package exists, nothing to do: $name $version "
546
+ }
547
+ else {
548
+ Write-UpliftMessage " `t`t package does not exist, installing: $name $version "
526
549
527
- if ([System.String ]::IsNullOrEmpty($version ) -eq $true ) {
528
- Install-Module - Name $name - Force;
529
- } else {
530
- Install-Module - Name $name - RequiredVersion $version - Force;
531
- }
550
+ if ([System.String ]::IsNullOrEmpty($version ) -eq $true ) {
551
+ Install-Module - Name $name - Force;
552
+ } else {
553
+ Install-Module - Name $name - RequiredVersion $version - Force;
532
554
}
555
+ }
533
556
534
- Write-UpliftMessage " `t [$attempt /$maxAttempt ] finished installing package: $name $version "
535
- $success = $true
536
- } catch {
537
- $exception = $_.Exception
557
+ Write-UpliftMessage " `t [$attempt /$maxAttempt ] finished ensuring package: $name $version "
558
+ $success = $true
559
+ } catch {
560
+ $exception = $_.Exception
538
561
539
- Write-UpliftMessage " `t [$attempt /$maxAttempt ] coudn't install package: $name $version "
540
- Write-UpliftMessage " `t [$attempt /$maxAttempt ] error was: $exception "
562
+ Write-UpliftMessage " `t [$attempt /$maxAttempt ] coudn't install package: $name $version "
563
+ Write-UpliftMessage " `t [$attempt /$maxAttempt ] error was: $exception "
541
564
542
- $attempt = $attempt + 1
543
- }
565
+ $attempt = $attempt + 1
544
566
}
567
+ }
545
568
546
- if ($success -eq $false ) {
547
- $errorMessage = " `t [$attempt /$maxAttempt ] coudn't install package: $name $version "
569
+ if ($success -eq $false ) {
570
+ $errorMessage = " `t [$attempt /$maxAttempt ] coudn't install package: $name $version "
548
571
549
- Write-UpliftMessage $errorMessage
550
- throw $errorMessage
572
+ Write-UpliftMessage $errorMessage
573
+ throw $errorMessage
574
+ }
575
+ }
576
+
577
+ function Install-UpliftPSModules {
578
+
579
+ Param (
580
+ [Parameter (Mandatory = $True )]
581
+ $packages
582
+ )
583
+
584
+ foreach ($package in $packages ) {
585
+
586
+ $name = $package [" Id" ]
587
+ $version = $package [" Version" ]
588
+
589
+ if ($version -is [System.Object []]) {
590
+
591
+ foreach ($versionId in $version ) {
592
+ Install-UpliftPSModule $name $versionId
593
+ }
594
+
595
+ } else {
596
+ Install-UpliftPSModule $name $version
551
597
}
552
598
}
553
599
}
0 commit comments