Skip to content

Commit 8de6b6f

Browse files
authored
Merge pull request #20 from agreenbhm/patch-1
Added token generation compatibility for Linux & MacOS
2 parents b70e349 + 4f8ae95 commit 8de6b6f

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

PSGuacamole/Public/APIConnection/New-GuacToken.ps1

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,22 @@ Function New-GuacToken()
3939
if ($Null -eq $Password -or $Password.Length -eq 0)
4040
{
4141
$SecurePassword = Read-Host "Enter password" -AsSecureString
42-
43-
# Decode SecureString to Plain text for Guacamole (https://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text)
44-
# Create a "password pointer"
45-
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
46-
47-
# Get the plain text version of the password
48-
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
49-
50-
# Free the pointer
51-
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
42+
# If running on Windows
43+
if ($IsWindows)
44+
{
45+
# Decode SecureString to Plain text for Guacamole (https://www.powershelladmin.com/wiki/Powershell_prompt_for_password_convert_securestring_to_plain_text)
46+
# Create a "password pointer"
47+
$PasswordPointer = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecurePassword)
48+
49+
# Get the plain text version of the password
50+
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto($PasswordPointer)
51+
52+
# Free the pointer
53+
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($PasswordPointer)
54+
# If running on Linux of MacOS
55+
} else {
56+
$Password = ConvertFrom-SecureString -SecureString $SecurePassword -AsPlaintext
57+
}
5258
}
5359

5460
$Body = @{

0 commit comments

Comments
 (0)