Strange ESXI issue

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 3 years and 10 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.
Taclan2022
Posts: 9
Last visit: Tue Jul 25, 2023 8:36 am

Strange ESXI issue

Post by Taclan2022 »

Product, version and build: PowerShell Studio 2020 Ver. 5.7.178 x64
Operating system: Creating form exe on Win 10 x64, running it on Server 2016 x64.

I originally posted on the GUI forum, jvierra recommended reposting on the support forum.

This is a link to that post: viewtopic.php?f=21&t=14818

Any insight would be appreciated. Thanks.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Strange ESXI issue

Post by Alexander Riedel »

From what I understand the command completes correctly when run in a console exe.
There are some rare cmdlets in modules which make an assumption that a console object exists.
A Windows process in general has no console just by definition. Other cmdlets assume that the progress indicator is character and console based, which also is not always true.
It is of course possible that there is something else at play here, but these are the most common conditions for such a behavior, rare as they are.

I understand that this is frustrating, as it puts you in the middle between us saying "It's not our problem" and the other vendor who probably would say "It works fine in the console".
It is quite possible that your only solution is to use two different processes to run this from a Windows Forms application.

Before we go there though, let's see if we can find out more. You state:
"I did get to run correctly by compiling the code in a separate .exe with a script engine option of "Windows Application" then calling it from my winform based exe."
Can you be more specific as to what exact engine and settings you chose for that?
Alexander Riedel
SAPIEN Technologies, Inc.
Taclan2022
Posts: 9
Last visit: Tue Jul 25, 2023 8:36 am

Re: Strange ESXI issue

Post by Taclan2022 »

I had the same thoughts about being between two vendors. I appreciate you guys assisting from your side.

Here are my engine settings:

For my winforms .exe the Script engine settings are:
Target: Microsoft Windows 64 Bit
Script Engines: Windows Powershell SAPIEN Powershell V5 Host (Windows Forms)
Use STA Mode (Powershell engines only): Checked

For the .exe that the winform calls, all settings are the same except:
Script Engines: Windows Powershell SAPIEN Powershell V5 Host (Windows Application)

I also tried putting the code back into my Winforms exe and changing the engine to Windows Powershell SAPIEN Powershell V5 Host (Windows Application) so that it popped open an output window. It locked up doing that too.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Strange ESXI issue

Post by Alexander Riedel »

I have been there plenty of times myself. It can be quite a challenge :D

Your result rules out the presence of a console to be the cause. A Windows Application also has no console.
Unfortunately I cannot test this here, so we have to take it one step at a time.
Can you package the secondary exe also as Windows Forms and try that? It won't make much difference other than that is will produce no visible output.
You will have to check in the code executing the secondary exe if it finishes, assuming you don't already do that anyway.

If that also succeeds, it is most certainly not associated with any particular type of output. The likely candidates for the problem then are threading and runspaces.
By definition, running the task in a different process will run it in a different runspace and thread.
You can potentially do that from within your Windows Forms app as well.
There can be other issues I have not thought of, so don't get your hopes up just yet.
Alexander Riedel
SAPIEN Technologies, Inc.
Taclan2022
Posts: 9
Last visit: Tue Jul 25, 2023 8:36 am

Re: Strange ESXI issue

Post by Taclan2022 »

Changing the secondary .exe to winform engine, the code works.
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Strange ESXI issue

Post by Alexander Riedel »

mmhmm. I would suggest to execute the code in question in a separate runspace next.
This might be of help if you are not familiar with that mechanism.
https://stackoverflow.com/questions/560 ... -functions
Alexander Riedel
SAPIEN Technologies, Inc.
Taclan2022
Posts: 9
Last visit: Tue Jul 25, 2023 8:36 am

Re: Strange ESXI issue

Post by Taclan2022 »

I'm not familiar with runspaces. I'll give it a go and let you know. Thanks!
Taclan2022
Posts: 9
Last visit: Tue Jul 25, 2023 8:36 am

Re: Strange ESXI issue

Post by Taclan2022 »

Not sure if I did this optimally but it works.
  1. $Runspace = [runspacefactory]::CreateRunspace()
  2.                  $PowerShell = [powershell]::Create()
  3.                  $PowerShell.runspace = $Runspace
  4.                  $Runspace.Open()
  5. [void]$PowerShell.AddScript({
  6.                 #Gathering ESXI info
  7.                 $JSONData = (Get-Content -RAW -Path c:\myapp\my.json | ConvertFrom-JSON)
  8.                 $Creds = $JSONData.setup.ESXi1.RootPW
  9.                 $ESX1Name = $JSONData.setup.ESXi1.Name             
  10.                 #Connecting to ESXI host and setting VIB policy
  11.                 (Connect-VIServer -Server $ESX1Name -User 'root' -Password "$Creds")
  12.                 $esxcli = (Get-EsxCli -V2)
  13.                 $esxcli.software.acceptance.set.Invoke(@{ level = 'PartnerSupported' })
  14.                  })
  15.                $PowerShell.BeginInvoke()
  16.                $PowerShell.Dispose()
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

Re: Strange ESXI issue

Post by Alexander Riedel »

Glad to hear you got it solved!
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 3 years and 10 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.