Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Import Module fails when home./config is not present #61

Open
ikiris04 opened this issue Jan 19, 2023 · 1 comment
Open

Import Module fails when home./config is not present #61

ikiris04 opened this issue Jan 19, 2023 · 1 comment

Comments

@ikiris04
Copy link

[chrischua@X-p1vnc0 PIM]$ pwsh
PowerShell 7.3.1
PS /users/[email protected]/GIT/ops-scripts/PIM> $psversiontable

Name Value


PSVersion 7.3.1
PSEdition Core
GitCommitId 7.3.1
OS Linux 4.18.0-372.32.1.el8_6.x86_64 #1 SMP Fri Oct 7 12:35:10 EDT 2022
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS /users/chrischua> get-module -listavailable MSAL.PS

Directory: /usr/local/share/powershell/Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands


Script 4.37.0.0 MSAL.PS Core,Desk {Add-MsalClientApplication, Clear-MsalTokenCache, Enable-MsalTokenCacheOnDisk, Get-MsalAccount…}

PS /users/chrischua> $debugPreference='Continue'
PS /users/chrischua> import-module MSAL.PS
Join-Path: /usr/local/share/powershell/Modules/MSAL.PS/4.37.0.0/internal/Import-Config.ps1:21
Line |
21 | … = Join-Path ([System.Environment]::GetFolderPath([System.Environment+ …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Cannot bind argument to parameter 'Path' because it is an empty string.
Join-Path: /usr/local/share/powershell/Modules/MSAL.PS/4.37.0.0/internal/Import-Config.ps1:22
Line |
22 | $Path = Join-Path $AppDataDirectory $Path
| ~~~~~~~~~~~~~~~~~
| Cannot bind argument to parameter 'Path' because it is null.

The command returns null because [System.Environment+SpecialFolder]::ApplicationData) is mapping to home/.config and if home/.config doesn't exist, it returns null
https://developers.redhat.com/blog/2018/11/07/dotnet-special-folder-api-linux#environment_getfolderpath

@ikiris04
Copy link
Author

I believe the following needs to be modified in import-config.ps1

  1. passing a DoNotVerify option to getfolderpath
  2. Create the directory if needed

$AppDataDirectory = Join-Path ([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::ApplicationData,[System.Environment+SpecialFolderOption]::DoNotVerify)) 'MSAL.PS'
[system.io.directory]::CreateDirectory($AppDataDirectory)
$Path = Join-Path $AppDataDirectory $Path

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant