Invoke-command issue

Hello.

I’m trying to invoke-command a script on a remote system using my domain admin cred but it fails to progress

$cred=get-credential
$comp=read-host “hostname”
icm -cn $comp -cred $cred -FilePath \company\global\software\Allowed_Apps\oracle\database\19c\Oracle_prep_install.ps1

\company\global\software\Allowed_Apps\oracle\database\19c\Oracle_prep_install.ps1 looks like below

#CREATE THE ORACLE DIRECTORY
Write-host “Creating Oracle directory” -foreground Green
New-Item -Path C:\Oracle -ItemType directory

#Copy files
Write-host “Copying Oracle files” -foreground Green
copy-item -verbose -Recurse \company\global\software\Allowed_Apps\oracle\database\19c*.* C:\oracle

#Unzip Oracle archive
Write-host “Extracting Oracle Install files” -foreground Green
Expand-Archive C:\Oracle\WINDOWS.X64_193000_db_home.zip -DestinationPath C:\Oracle

The script will create the C:\Oracle dir but systematically fails to copy the files if run via invoke-command with no errors. However, it will proceed if I import a pssession with the exact same admin credentials and call the Oracle_prep_install script.

What am I doing wrong ?

Thanks
G

Gaetan,
Welcome to the forum. :wave:t4:

If you are remoting to another computer you cannot remote from there to a third computer by default. That’s known as double hop problem.

To avoid this you could instead transfer the needed files to the target computer in advance and access them “locally” when you run your script.

BTW: When you post code please format it as code using the preformatted text button ( </> ). Place the cursor on an empty line, click the button and paste your code. Otherwise the forum software will try to “interpret” your code as HTML or MarkUp tags and remove some charachters. :wink:
Thanks in advance.

1 Like

Thank you Olaf and I will post code as advised in the future