From 1c745fc7b500297d41d72b8e9448dc4130616d88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Tue, 3 Sep 2024 11:15:04 +0200 Subject: [PATCH] Fix Powershell 5 -AsPLainText on ConvertFrom-SecureString --- PowerFGT/Public/cmdb/user/local.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/PowerFGT/Public/cmdb/user/local.ps1 b/PowerFGT/Public/cmdb/user/local.ps1 index 0f4e27d8f..a04cd3048 100644 --- a/PowerFGT/Public/cmdb/user/local.ps1 +++ b/PowerFGT/Public/cmdb/user/local.ps1 @@ -79,7 +79,13 @@ function Add-FGTUserLocal { } if ($PsBoundParameters.ContainsKey('passwd')) { - $password = ConvertFrom-SecureString -SecureString $passwd -AsPlainText + if (("Desktop" -eq $PSVersionTable.PsEdition) -or ($null -eq $PSVersionTable.PsEdition)) { + $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($passwd); + $password = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr); + } + else { + $password = ConvertFrom-SecureString -SecureString $passwd -AsPlainText + } } if ( Get-FGTUserLocal @invokeParams -name $name -connection $connection) {