pspete / PoShPACLI

Powershell Module for CyberArk PACLI
MIT License
72 stars 19 forks source link

Workingdirectory in Invoke-PACLICommand #51

Closed KimChr closed 5 years ago

KimChr commented 6 years ago

Hi Pete,

I have had some troubles with the FIND-PVFILE function. PACLI crashes every time I call the function. It is the same with Disconnect-PVVault. And other functions I have not used yet, I guess. I found out that PACLI needs the workingdirectory to be where PACLI.exe, and dependent files are. So I changed the Invoke-PACLICommand.ps1 to include this line: $PacliProcess.StartInfo.WorkingDirectory = ([System.IO.Path]::GetDirectoryName($PacliEXE)) And now it works :-)

Please change this in the next update.

pspete commented 6 years ago

Hi @KimChr - Can you provide some example code where you see the behavior so I can attempt to recreate the issue? The verbose/debug output may also be useful.

KimChr commented 6 years ago

Hi Pete,

I have this simple code:

$UserName = "Script"
$PacliVault = "MyVault"
$PacliAddress = "192.168.116.11"

Import-Module '.\PoShPACLI-master\PoShPACLI'

$PacliPath = (Resolve-Path -Path ".\Pacli.9.99").Path
$Res = Initialize-PoshPacli -pacliFolder $PacliPath
$Res = Start-PVPacli
$Res = New-PVVaultDefinition -vault $PacliVault -address $PacliAddress
$Res = Connect-PVVault -vault $PacliVault -user $UserName -password (Read-Host -AsSecureString)
$Res = Disconnect-PVVault -vault $PacliVault -user $UserName
$Res = Stop-PVPacli

When the "Disconnect-PVVault" is called I get this error: ERROR: Disconnect-PVVault : Cannot communicate with PACLI server. Issue PACLI init. error code: 17 The PACLI.exe process is killed and I get an Application Error event id 100 in the eventlog.

Debug output:

DEBUG: Processing Bound Parameters
DEBUG: PACLI Command: INIT
DEBUG: Exit Code: 0
DEBUG: Processing Bound Parameters
DEBUG: vault="MyVault" address="192.168.116.11"
DEBUG: PACLI Command: DEFINE vault="MyVault" address="192.168.116.11"
DEBUG: Exit Code: 0
DEBUG: Processing Bound Parameters
DEBUG: vault="MyVault" user="Script" password="CyberArk1"
DEBUG: PACLI Command: LOGON vault="MyVault" user="Script" password="*******"
DEBUG: Exit Code: 0
DEBUG: Processing Bound Parameters
DEBUG: vault="MyVault" user="Script"
DEBUG: PACLI Command: LOGOFF vault="MyVault" user="Script"
DEBUG: Exit Code: -1
DEBUG: Processing Bound Parameters
DEBUG: PACLI Command: TERM
DEBUG: Exit Code: -1

I see the same error when I run a PACLI cmd batch script, if I don't CD or PushD to the PACLI directory before running the PACLI commands.

pspete commented 6 years ago

Thanks for that @KimChr....

From your code, am i right in assuming you are running PACLI 9.99? I have not yet got the module to work properly with any version of PACLI more recent than 7.2.x Perhaps your suggested fix will provide some progress in that respect....

This may also relate to #48

KimChr commented 6 years ago

Yes, you are right, I run PACLI 9.99, but I have tried with all the versions from 7.2 and up. It is the same problem with them all.