PowerCLI

 View Only
  • 1.  PowerCLI cmdlets pass through powershell

    Posted Dec 19, 2023 10:21 AM

    Hello! This is my first time posting something on this forum, if i do break any rule of conduct by accident please let me know.

    I have an issue where I'm trying to pass PowerCLI cmdlets through a powershell session. The session is initiated by a 3rd party program called "ActiveXpert network monitor" and it happens whenever a specific criteria is true (like my local machines CPU usage is too high or something).

    Whenever a criteria is fullfilled, ActiveXpert starts an Action response and starts up a powershell.exe interpreter and executes the code below:

    Start-Transcript -Path "C:\Windows\System32\WindowsPowerShell\v1.0\Log.txt"                     <-- used for logging
    Set-Location "C:\ProgramData\ActiveXperts\Network Monitor\Scripts"                                       <-- script location where pwshell will look
    icacls "C:\ProgramData\ActiveXperts\Network Monitor\Scripts\Action (ps1)\temp.xml" /grant "NT AUTHORITY\SYSTEM:(F)" <-- granting user account SYSTEM full access to a credentialsfile
    $CredFile =Get-VICredentialStoreItem -File C:\ProgramData\ActiveXperts\Network Monitor\Scripts\Action (ps1)\temp.xml     <-- retrieves it from specified path
    $hosts =$CredFile.Host          Hosts name
    $user =$CredFile.User            Name for User accessing the host
    $pass =$CredFile.Password   Password for User accessing the host
    Connect-VIServer -Server $hosts -User $user -Password $pass       <-- passing credentials retrieved
    Start-VM -VM "random VM name"                                  <-- starting up specific VM name
    Disconnect-VIServer -Confirm:$false                           <-- disconnecting from server host without prompts
    Stop-Transcript                                                     <-- stops all logging

    The script essentially uses installed PowerCLI module cmdlets to pass through in Powershell (because the ActiveXpert program can only initiate Powershell or Visual Studio or Windows Batch File).


    So what's the issue? Well if you start up a powershell session and execute the script above in the shell, it works fine. But executing the same script from Activexpert, that is starting it's own powershell session and executing the script in it, generates an error saying "Get-VICredentialStoreItem: the specified path does not exist" even though it's fully fleshed out in the script. I'm running PowerCLI modules version 13.2 which should be compatible with my ESXI hosts that's at least version 6.7 and I'm also running 5.1 powershell version.

    Other than setting executionpolicies to unrestricted and trying to add an enviroment variable for it to look in, I can't think of anything else. Does this issue seem familliar? If so what are your suggesstions?



  • 2.  RE: PowerCLI cmdlets pass through powershell

    Posted Dec 19, 2023 06:49 PM

    Did you try placing quotes around the path, since it seems to contain a blank?

    $CredFile =Get-VICredentialStoreItem -File 'C:\ProgramData\ActiveXperts\Network Monitor\Scripts\Action (ps1)\temp.xml'


  • 3.  RE: PowerCLI cmdlets pass through powershell

    Posted Dec 21, 2023 12:10 PM

    Hello Luc!

    Yes i surronded the path with double quotation marks like this 

    "C:\ProgramData\ActiveXperts\Network Monitor\Scripts\Action (ps1)\temp.xml"

    For some reason i guess it didnt follow when i first made the post.



  • 4.  RE: PowerCLI cmdlets pass through powershell

    Posted Dec 21, 2023 12:25 PM

    I'm afraid I don't know how this monitoring tool starts PS scripts.
    Don't they have a forum where you can ask this question?
    This doesn't look like a PowerCLI issue.