@@ -142,20 +142,53 @@ function Initialize-OSDCloudStartnet {
142142            }
143143        }
144144
145-         #  Check if the OSD Module in the PowerShell Gallery is newer than the installed version
146-         $TimeSpan  =  New-TimeSpan  - Start $Global :StartnetStart  - End (Get-Date )
147-         Write-Host  - ForegroundColor DarkGray " $ ( $TimeSpan.ToString  (" mm':'ss" )  Updating OSD PowerShell Module" 
148-         $PSModuleName  =  ' OSD' 
149-         $InstalledModule  =  Get-Module  - Name $PSModuleName  - ListAvailable - ErrorAction Ignore |  Sort-Object  Version - Descending |  Select-Object  - First 1 
150-         $GalleryPSModule  =  Find-Module  - Name $PSModuleName  - ErrorAction Ignore - WarningAction Ignore
151- 
152-         #  Install the OSD module if it is not installed or if the version is older than the gallery version
153-         if  ($GalleryPSModule ) {
154-             if  (($GalleryPSModule.Version   -as  [version ]) -gt  ($InstalledModule.Version   -as  [version ])) {
155-                 Write-Host  - ForegroundColor DarkGray " $PSModuleName  $ ( $GalleryPSModule.Version  )  [AllUsers]" 
156-                 Install-Module  $PSModuleName  - Scope AllUsers - Force - SkipPublisherCheck
157-                 Import-Module  $PSModuleName  - Force
145+         Write-Host  - ForegroundColor Cyan ' [i] Config Post StartNet Scripts' 
146+         $Global :ScriptStartNet2  =  Get-PSDrive  - PSProvider FileSystem |  Where-Object  { $_.Name   -ne  ' C' |  ForEach-Object  {
147+             Write-Host  - ForegroundColor DarkGray " $ ( $_.Root  ) OSDCloud\Config\Scripts\StartNet2\*.ps1" 
148+             Get-ChildItem  " $ ( $_.Root  ) OSDCloud\Config\Scripts\StartNet2\" - Include " *.ps1" - File - Recurse - Force - ErrorAction Ignore
149+         }
150+         if  ($Global :ScriptStartNet2 ) {
151+             $Global :ScriptStartNet2  =  $Global :ScriptStartNet2  |  Sort-Object  - Property FullName
152+             foreach  ($Item  in  $Global :ScriptStartNet2 ) {
153+                 Write-Host  - ForegroundColor Gray " Execute $ ( $Item.FullName  ) " 
154+                 &  " $ ( $Item.FullName  ) " 
155+             }
156+             $TimeSpan  =  New-TimeSpan  - Start $Global :StartnetStart  - End (Get-Date )
157+             Write-Host  - ForegroundColor DarkGray " $ ( $TimeSpan.ToString  (" mm':'ss" )  Tried to execute Post StartNet Scripts" 
158+         }
159+ 
160+         Write-Host  - ForegroundColor Cyan ' [i] OSD module update' 
161+         $Global :OSDModuleUpdate  =  $true  #  Default is trying to newer OSD module
162+         $Global :OSDCloudStartnetJson  =  Get-PSDrive  - PSProvider FileSystem |  Where-Object  {$_.Name   -ne  ' C' |  ForEach-Object  {
163+             Get-ChildItem  " $ ( $_.Root  ) OSDCloud\Config" - Include " Initialize-OSDCloudStartnet.json" - File - Force - Recurse - ErrorAction Ignore
164+         }
165+         if  ($Global :OSDCloudStartnetJson  ) {
166+             foreach  ($Item  in  $Global :OSDCloudStartnetJson ) {
167+                 Write-Host  - ForegroundColor DarkGray " $ ( $Item.FullName  ) " 
168+                 $Global :OSDModuleUpdate  =  (Get-Content  - Path " $ ( $Item.FullName  ) " |  ConvertFrom-Json  - ErrorAction " Stop" 
169+                 Write-Host  - ForegroundColor DarkGray " - OSDAutoUpdate: $ ( $Global :OSDModuleUpdate ) " 
158170            }
159171        }
172+         if  ($Global :OSDModuleUpdate ) {
173+             #  Check if the OSD Module in the PowerShell Gallery is newer than the installed version
174+             $TimeSpan  =  New-TimeSpan  - Start $Global :StartnetStart  - End (Get-Date )
175+             Write-Host  - ForegroundColor DarkGray " $ ( $TimeSpan.ToString  (" mm':'ss" )  Updating OSD PowerShell Module" 
176+             $PSModuleName  =  ' OSD' 
177+             $InstalledModule  =  Get-Module  - Name $PSModuleName  - ListAvailable - ErrorAction Ignore |  Sort-Object  Version - Descending |  Select-Object  - First 1 
178+             $GalleryPSModule  =  Find-Module  - Name $PSModuleName  - ErrorAction Ignore - WarningAction Ignore
179+ 
180+             #  Install the OSD module if it is not installed or if the version is older than the gallery version
181+             if  ($GalleryPSModule ) {
182+                 if  (($GalleryPSModule.Version   -as  [version ]) -gt  ($InstalledModule.Version   -as  [version ])) {
183+                     Write-Host  - ForegroundColor DarkGray " $PSModuleName  $ ( $GalleryPSModule.Version  )  [AllUsers]" 
184+                     Install-Module  $PSModuleName  - Scope AllUsers - Force - SkipPublisherCheck
185+                     Import-Module  $PSModuleName  - Force
186+                 }
187+             }
188+         } else  {
189+             #  if json contains {"OSDAutoUpdate": false} then not trying to import newer OSD module
190+             $TimeSpan  =  New-TimeSpan  - Start $Global :StartnetStart  - End (Get-Date )
191+             Write-Host  - ForegroundColor DarkGray " $ ( $TimeSpan.ToString  (" mm':'ss" )  Skip Updating OSD PowerShell Module" 
192+         }
160193    }
161194}
0 commit comments