Error setting property only after compiling into exe

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 8 years and 1 month 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
vvpham@powershellstudio
Posts: 3
Last visit: Sun Feb 12, 2023 1:15 pm

Error setting property only after compiling into exe

Post by vvpham@powershellstudio »

Product, version and build: SAPIEN PowerShell Studio 2015, 4.2.99
32 or 64 bit version of product: 64
Operating system: Windows 7 Enterprise SP (PowerShell v3)
32 or 64 bit OS: 64

GOAL: Create a GUI that passes sensitive credentials in an environment with PowerShell Event logging enabled but hides the details in the Event Viewer logs so the credentials cannot be reversed engineered from the event log details.

SCRIPT:

(Get-Module Microsoft.PowerShell.Security).LogPipelineExecutionDetails = $false
$user = "Domain\AdminUser"
$key = [array]"values"
$pwd = ConvertTo-SecureString "encryptedstring" -Key $key
$credentials = New-Object System.Management.Automation.PsCredential($user, $pwd)
(Get-Module Microsoft.PowerShell.Security).LogPipelineExecutionDetails = $True

ISSUE: When running the following lines in PowerShell script, the script behaves as expected: script disables event log details recording, credential object is created successfully, event log details are then re-enabled. However, the same code is then packaged in PowerShell Studio (Settings for package are: SAPIEN PowerShell V3 Host (Windows) x64, STA Mode)), the executable generates an error when ran. This error reads: ERROR: Property 'LogPipelineExecutionDetails' cannot be found on this object; make sure it exists and is settable. This error occurs when trying to set this property to false and true.

NOTES: This executable is being ran as an administrator on the system and again, the script works fine until packaged into an executable by PowerShell Studio.

Any help would be greatly appreciated. Or, if anyone has any idea on how to otherwise hide credential details from the event log so they cannot be reversed engineered. Clearing the event log (even time-based on just when the script was being ran was not considered an acceptable solution).
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Error setting property only after compiling into exe

Post by Alexander Riedel »

"script runs fine" does not imply where you ran it. If you ran this in the powershell console, please note that the console by default runs elevated.
That is a step above logged on as administrator.

Secondly, do not write code like this:
(Get-Module Microsoft.PowerShell.Security).LogPipelineExecutionDetails

You assume that the Get-Module call ALWAYS works and that the module is actually already imported.
  1. if(!(Get-Module Microsoft.PowerShell.Security)) {
  2.  Import-Module Microsoft.PowerShell.Security
  3. }
  4.  
  5. $Module = Get-Module Microsoft.PowerShell.Security
  6. if($Module) {
  7.   $Module.LogPipelineExecutionDetails  = $false
  8. }
This gives you a chance to see where it fails, if it fails
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 8 years and 1 month 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.