Using embedded credentials in PowerShell

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
osh-sapienreg
Posts: 1
Last visit: Tue Jun 28, 2022 2:59 pm

Using embedded credentials in PowerShell

Post by osh-sapienreg »

Product: PowerShell Studio 2022 (64 Bit)
Build: v5.8.207
OS: Windows Server 2019 Datacenter (64 Bit)
Build: v10.0.17763.0

PSVersion: 5.1.17763.2931

I'm trying to package an with a PowerShell script that need passwords provided

It didn't work - here's a simple example with no real credentials (script1.png)
simple script 1
simple script 1
script1.png (11.56 KiB) Viewed 2492 times
Write-Host User: $SAPIENHost.GetUserID(0)
Write-Host Pass: $SAPIENHost.GetPasswordString(0)


Nothing fancy...

Here's where the UserID and PasswordString are configured in the build (script2.png)
creds in build for simple script 1
creds in build for simple script 1
script2.png (21.13 KiB) Viewed 2492 times
And the results (script3.png) once the exe is built
results of simple script1
results of simple script1
script3.png (30.68 KiB) Viewed 2492 times
You cannot call a method on a null-valued expression.
At C:\Windows\system32\43449C22.ps1:13 char:1
+ Write-Host User: $SAPIENHost.GetUserID(0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Windows\system32\43449C22.ps1:14 char:1
+ Write-Host Pass: $SAPIENHost.GetPasswordString(0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull




Aside: this script works fine
$var_id = "newUserName"
$var_pw = "PASSWORD OBFUSCATED"

Write-Host User: $var_id
Write-Host Pass: $var_pw
User avatar
brittneyr
Site Admin
Posts: 1654
Last visit: Wed Mar 27, 2024 1:54 pm
Answers: 39
Been upvoted: 30 times

Re: Using embedded credentials in PowerShell

Post by brittneyr »

Does your script work as expected when you run it in PowerShell Studio?
Brittney
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Using embedded credentials in PowerShell

Post by Alexander Riedel »

From this error: At C:\Windows\system32\43449C22.ps1:13 char:1
I can tell that you selected a script engine that uses a temporary file and not one with a SAPIEN Script Host.
In all likelihood this one:
2022-06-28_17-10-34.png
2022-06-28_17-10-34.png (162.67 KiB) Viewed 2476 times
So the variable $SAPIENHost does not exist in this case.

Only hosts with the words 'SAPIEN' and 'Host' have that particular object.
2022-06-28_17-12-29.png
2022-06-28_17-12-29.png (33.9 KiB) Viewed 2476 times
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 1 year and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.