Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

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 7 years and 4 weeks 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.
User avatar
sylvain1515
Posts: 3
Last visit: Fri Jun 07, 2019 6:27 am

Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by sylvain1515 »

Hi,

Why if I execute this line $Host.ui.PromptForCredential("Windows Title", "Username + Password", "$ENV:Username", "My_Domain", "Default", "Default") with PowerShell Studio 2017 v5.4.136 I am getting username without the domain.

If I do the same command with Windows Powershell ISE the username return by the function always include "My_domain" or another domain if I input one.
Also the Windows Powershell ISE function is doing some Username validation.

Windows Powershell ISE version
Major Minor Build Revision
----- ----- ----- --------
5 1 14393 693

Thank you
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by jvierra »

See the following:https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Also - I cannot reproduce your issue. "Default" is not a concise target.
User avatar
sylvain1515
Posts: 3
Last visit: Fri Jun 07, 2019 6:27 am

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by sylvain1515 »

Hi,

I am running all my test on Windows 10 Enterprise 64 bits system.
The same issue with 2 workstations. On the first one Sapien Powershell Studio 2017 is activated and second one is a trial version.

File test.ps1 contents:

Clear-Host
$PSVersionTable
$CredentialType = [System.Management.Automation.PSCredentialTypes]::Domain
$ValidateOption = [System.Management.Automation.PSCredentialUIOptions]::ValidateUserNameSyntax
$credentialType
$ValidateOption
$Cred = $Host.ui.PromptForCredential("Title", "Username password", "$ENV:Username", "MyDomain", $CredentialType, $ValidateOption)
$Cred.Username

When running test.ps1 with Windows PowerShell ISE and click CANCEL when it prompt the user the output:

Name Value
---- -----
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Domain
Default

When running test.ps1 from Sapien PowerShell Studio 2017 and click CANCEL when it prompt the user the output are:

>> Running (test.ps1) Script...
>> Platform: V5 64Bit

Name Value
---- -----
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Domain
Default
ERROR: Exception calling "PromptForCredential" with "6" argument(s): "Object reference not set to an instance of an object."
test.ps1 (6, 1): ERROR: At Line: 6 char: 1
ERROR: + $Cred = $Host.ui.PromptForCredential("Title", "Username password", "$ ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
ERROR: + FullyQualifiedErrorId : NullReferenceException
ERROR:

>> Execution time: 00:00:02
>> Script Ended
>> Max. CPU: 1 % Max. Memory: 17.26 MB
>> Running (test.ps1) Script...

==============================================================================

Now if I rerun the test.ps1 and type a username and password.

With Windows PowerShell ISE output:

Name Value
---- -----
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Domain
Default
MyDomain\guest


With Sapien PowerShell Studio 2017 output are:

>> Running (test.ps1) Script...
>> Platform: V5 64Bit

Name Value
---- -----
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Domain
Default
guest

>> Execution time: 00:00:06
>> Script Ended
>> Max. CPU: 1 % Max. Memory: 14.07 MB

==============================================================================

Why I do not see the DOMAIN "MyDomain" in front of the username when running with Sapien PowerShell Studio 2017 ?
Why the error "ERROR: Exception calling "PromptForCredential" with "6" argument(s): "Object reference not set to an instance of an object."" with Sapien PowerShell Studio 2017 ?
Why there is username validation with Windows Powershell ISE ? if I enter Username with ";" example "guest ;" and nothing with with Sapien PowerShell Studio 2017 ?

Why this incompatibility ?


Thanks
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by jvierra »

I recommend using the full command which works correctly.

$cred=Get-Credential mydomain\$env:USERNAME
$cred.UserName
User avatar
sylvain1515
Posts: 3
Last visit: Fri Jun 07, 2019 6:27 am

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by sylvain1515 »

Yes, I agree, but that does not explain why there are different results.
I liked the ability to customize and get-credential does not allow it.
By the way, the scripts that worked before under Windows Powershell ISE or PowerGUI Script Editor must be adapted to work under Powershell Studio 2017!
Weird
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by Alexander Riedel »

Different hosts have a different implementation. Since Microsoft does not exactly document these things well, it always involves guesswork.
In general calling host methods directly rather than using cmdlets will always be a source of differences. Some modification on the host are necessary to accommodate different platforms.
We will investigate and see what we can find out.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Windows PowerShell ISE vs PowerShell Studio 2017 v5.4.136 result are different

Post by Alexander Riedel »

For future reference, if you have a product specific question please post in the corresponding product forum rather than in the general PowerShell forum.
You will get a faster answer and the PowerShell forum stays on topic for questions related to PowerShell itself. Thanks!
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 7 years and 4 weeks 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.