itglue / powershellwrapper

This PowerShell module acts as a wrapper for the IT Glue API.
Apache License 2.0
120 stars 51 forks source link

Cannot convert empty null to secure string #128

Closed ecspresso closed 3 years ago

ecspresso commented 3 years ago

Steps to reproduce

Import-Module -Name ITGlueAPI as nt_authority\system

Expected behavior

Import the module.

Actual behavior

ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\ITGlueAPI\2.1.0\Internal\ModuleSettings.ps1:33 char:61
+ ... ig.ITGlue_API_key = ConvertTo-SecureString $tmp_config.ITGlue_API_key
+                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSecureStringCommand

Environment

Please share additional details about your environment. Version information for:

Name Value
PSVersion 5.1.14393.4402
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.4402
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Name Value
OsName Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU StandardServerEdition
OsArchitecture 64-bit
WindowsBuildLabEx 14393.4402.amd64fre.rs1_release.210426-1725
OsLanguage en-US
OsMuiLanguages {en-US}
ecspresso commented 3 years ago

This seems to happen when there is no profile data and $tmp_config.ITGlue_API_key is null. Simply adding -ErrorAction SilentlyContinue should resolve this since you can set a variable to empty data but you cannot convert a null string.

ecspresso commented 3 years ago

ConvertTo-SecureString -String $null -Force -ErrorAction SilentlyContinue generates an error even with SilentlyContinue and that the module is still imported.

ecspresso commented 3 years ago

The issue here was that I managed to run Export-ITGlueModuleSettings with an API key set or in some other way create the config.psd1 file, causing an error when running the import.