diff --git a/RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/LoadModule.psm1 b/RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/LoadModule.psm1 index 8e3ab4ec9..68aab77c7 100644 --- a/RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/LoadModule.psm1 +++ b/RubrikSecurityCloud/RubrikSecurityCloud.PowerShell/LoadModule.psm1 @@ -1,8 +1,11 @@ # # Load Core DLL: # - try { + # Record the user's current working directory so that we can return to it when we + # are done loading the module + $currentPath = Get-Location + If ($PSVersionTable.PSEdition -eq "Desktop") { Write-Output("`nLoading Rubrik Security Cloud PowerShell Module (WindowsPowerShell)...`n") $moduleDir = Join-Path -Path $PSScriptRoot -ChildPath "net472" @@ -12,9 +15,12 @@ try { $moduleDir = Join-Path -Path $PSScriptRoot -ChildPath "net6.0" } - Write-Output "LoadModule.psm1: Import-Module $modulePath" + # To ensure that help files are loaded properly, we need to change directory to the + # desired platform build (i.e. net742 or net6.0) Set-Location -Path $moduleDir - $modulePath = Join-Path -Path $moduleDir -ChildPath "RubrikSecurityCloud.PowerShell.Dll" + $modulePath = Join-Path -Path $moduleDir -ChildPath "RubrikSecurityCloud.PowerShell.dll" + + Write-Output "LoadModule.psm1: Import-Module $modulePath" Import-Module $modulePath -ErrorAction Stop Write-Output("Welcome to the Rubrik Security Cloud PowerShell SDK!`n") @@ -24,3 +30,7 @@ try { catch { Write-Error("Unable to load Rubrik Security Cloud Module: " + $_) } +finally { + # Ensure the working directory has been set back to the original when the script exits + Set-Location $currentPath +} \ No newline at end of file