From c2cf5674f8c3ebda4db71ef563c7c60bf764bb88 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Wed, 12 Jun 2024 17:28:26 -0700 Subject: [PATCH] Updated module dependencies To enable the Wake flag, we need ConfigurationManager module. This was in the module manifest in Required Modules, however get-pc is functional without ConfigurationManager so it didn't make sense for get-pc to fail importing if ConfigurationManager wasn't present. Removing it from Required Modules and importing it at the bottom of Get-PC.psm1 allows the import to fail silently and the lost functionality isn't reported until user attempts to use the Wake flag (which is a good thing). --- Get-PC.psd1 | 2 +- Get-PC.psm1 | 3 +++ Private/Invoke-Wake.ps1 | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Get-PC.psd1 b/Get-PC.psd1 index 982b823..30ebe88 100644 --- a/Get-PC.psd1 +++ b/Get-PC.psd1 @@ -51,7 +51,7 @@ Copyright = '(c) 2019 Chuck Beddow. All rights reserved.' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -RequiredModules = @('ConfigurationManager') +# RequiredModules = @() # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() diff --git a/Get-PC.psm1 b/Get-PC.psm1 index 68eacb4..c41a632 100644 --- a/Get-PC.psm1 +++ b/Get-PC.psm1 @@ -18,3 +18,6 @@ ForEach ($folder in $functionFolders) } $publicFunctions = (Get-ChildItem -Path "$PSScriptRoot\Public" -Filter '*.ps1').BaseName Export-ModuleMember -Function $publicFunctions + +# Optional modules to import for certain functions +Import-Module ConfigurationManager # -Wake \ No newline at end of file diff --git a/Private/Invoke-Wake.ps1 b/Private/Invoke-Wake.ps1 index 0a618e9..be55e16 100644 --- a/Private/Invoke-Wake.ps1 +++ b/Private/Invoke-Wake.ps1 @@ -1,4 +1,8 @@ function Invoke-Wake($Computer) { + if (-not (Get-Module ConfigurationManager)) { + Write-Warning "ConfigurationManager module not available! Please install Configuration Manager Console to use this feature" + return + } Write-Host "Attemping to wake up $Computer, check in a few minutes" Push-Location Set-Location "$(Get-PSDrive -PSProvider CMSite)`:"