From 45f8c2c3593c97b57c651d635dfa44219d756698 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Tue, 10 Sep 2024 15:41:44 +0200 Subject: [PATCH] UserLocal: Fix change password with PS 5.0 --- 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 f2c9549b5..c262dbf4c 100644 --- a/PowerFGT/Public/cmdb/user/local.ps1 +++ b/PowerFGT/Public/cmdb/user/local.ps1 @@ -370,7 +370,13 @@ function Set-FGTUserLocal { if ($connection.version -ge "7.4.0") { Throw "Can't change passwd with FortiOS > 7.4.0 (Need to use Set-FGTMonitorUserLocalChangePassword)" } - $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 ( $PSCmdlet.ParameterSetName -ne "default" -and $userlocal.type -ne $PSCmdlet.ParameterSetName ) {