Powershell script with user interaction error

Started by domvalle@comcast.net, January 08, 2026, 11:08:28 AM

Previous topic - Next topic

domvalle@comcast.net

My first go at this powershell script. Not sure if I even have the correct idea but getting this COM/CLR error below: "the command type does not support user interaction"
Any ideas would be welcomed! thanks!

;                     - - - - - - need this - - - - - -
;a script that loads the PSFalcon module and sets up authentication with CrowdStrike Falcon APIs
;then looks up a hostname, and retrieves the uninstall token

clienID = "MyClientID"
Secret = "MySecret"

 loadMod = "Import-Module '\\severpath\PSFalcon'"
; * Module will Prompt for: clientid     ;prompt: secret
 prompt = "Request-FalconToken -ClientId ClientId -ClientSecret Secret"
;   Lookup Hostname return HostID
 xHost = "Get-FalconHost -Filter hostname:'MyComputerName'"
;   Retrieve uninstall token from HostID
 tok = "Get-FalconUninstallToken -Id xHost"

ObjectClrOption("useany", "System.Management.Automation")
objAutoPs = ObjectClrNew("System.Management.Automation.PowerShell")
oPshell = objAutoPs.Create()
oScope = ObjectType("BOOL",@TRUE)
;-----------------------------------------------------------------------
           ;can we run multiple cmds here?
pause("test", "beg load")
oPshell.AddScript(loadMod,oScope)        ;set cmd
objAsync = oPshell.BeginInvoke()         ;run cmd
oPShell.EndInvoke(objAsync)            ;close

pause("test", "beg prompt")
oPshell.AddScript(prompt,oScope)           ;set cmd
objAsync = oPshell.BeginInvoke()         ;run cmd
oPShell.EndInvoke(objAsync)            ;close

pause("test", "beg xHost")
oPshell.AddScript(xHost,oScope)           ;set cmd
objAsync = oPshell.BeginInvoke()      ;run cmd
oPShell.EndInvoke(objAsync)         ;close
;   ...at this line getting:
;   -->[WWWNT34I]
;   -->LastError=1060 (GetServiceKeyName)
;   -->[COM/CLR Exception]
;   -->System.Management.Automation=A command that prompts the user failed because the host program or the command type
;   -->does not support user interaction. The host was attempting to request confirmation with the following message:

pause("test", "beg tok")
oPshell.AddScript(tok,oScope)        ;set cmd
objAsync = oPshell.BeginInvoke()      ;run cmd
;-----------------------------------------------------------------------
oPShell.EndInvoke(objAsync)               ;close

spl

So, you are calling PS code from WB. Why not include that? My best guess is you let the PS code get the key and run the result. Not sure how WB would handle multiple PS commands, but possibly my Std_Out() function would suffice. You might be surprised.
Stan - formerly stanl [ex-Pundit]

domvalle@comcast.net

thanks stan!
I was able to string together, with a ;, these cmds that work from a ps cmd prompt but GetSTDOUT() does not like it: Keep getting: Wrong Number of Args! ...hmmm
                               data = GetSTDOUT("pwsh.exe -command %cmdStr%")

...however, this works directly from a PS Console:
pwsh.exe -command Import-Module \\serverpath\PSFalcon;Request-FalconToken -ClientId x0x0x0x0x0x0x -ClientSecret x0x0x0x0x0x0x;$xHost = Get-FalconHost -Filter "hostname:'MV-IT-6T149R3'";Get-FalconUninstallToken -Id $xHost

...btw, ps seems to insist that the var I want to use for xHost must be $xHost

spl

This will get tricky. You can probably write the whole thing in PS, but calling PS from WB with multiple commands..... hmmmm. My best guess, and only a guess, would be to place your powershell code into a scriptblock. I have used that structure for code working with JIRA ticketing, and am by no means competent with it. However, I expect Tony will comment that WB can handle the multiple commands with WB's CLR, and maybe PS won't be necessary.

Function CalledFromWB {
    [CmdletBinding(SupportsShouldProcess=$true)]
    param ($Parameter1)

    begin {
        # Initialization code here
    }

    process {
        # Code to process each input record
    }

    end {
        # Cleanup code here
    }
}
Stan - formerly stanl [ex-Pundit]

domvalle@comcast.net

thanks spl!...

OK, since I can run those lines directly in a ps cmd, I just save it to a .ps1, like was mentioned, and run stans 'PowerShell ps1 Script'. I then have to write the vars to files. The reason I wanted to do all in WB was to avoid writing sensitive data to a file.

For now this works fine except I have to make sure all those files are removed.

spl

Quote from: domvalle@comcast.net on January 11, 2026, 10:00:26 AMFor now this works fine except I have to make sure all those files are removed.

Yes, cleaning up would be the End section if you ran the PS as a script block. The one think I appreciated when I configured the STDOUT() udf was that WB could do cleanup. Not sure I really helped, but anyone bringing in PS into WB will have my full attention. It is the best 'extender' I can think of if used properly with CLR limitations. 
Stan - formerly stanl [ex-Pundit]

SMF spam blocked by CleanTalk