VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Not able to copy file from ESXi to Windows Folder

Hi,

I am trying to copy a file from ESXi host to my windows server, I am not able to copy

$serv = "192.168.15.200"
$Username = 'root'
$pass = ConvertTo-SecureString -AsPlainText 'password@123' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
$session = New-SSHSession $serv -Credential $Cred -AcceptKey -ErrorAction Stop
$connected = $session.Connected
Invoke-SSHCommand -SSHSession $session -Command 'mkdir /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'chmod 755 /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'cp /etc/passwd > /tmp/output'
Get-SCPItem -ComputerName $serv -Credential $Cred -Destination 'D:\logs\' -Path '/tmp/output/passwd' -Verbose -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command 'rm -rf /tmp/output/*.*'
Remove-SSHSession $session -Verbose | Out-Null

 

Output

ganapa2000_0-1657819919390.png

 

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are a couple of errors in your code.
Try like this

$serv = "192.168.15.200"
$Username = 'root'
$pass = ConvertTo-SecureString -AsPlainText 'password@123' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $pass
$session = New-SSHSession $serv -Credential $Cred -AcceptKey -ErrorAction Stop
$connected = $session.Connected
Invoke-SSHCommand -SSHSession $session -Command 'mkdir /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'chmod 755 /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'cp /etc/passwd /tmp/output'
Get-SCPItem -ComputerName $serv -Credential $Cred -Destination 'D:\logs\' -Path '/tmp/output/passwd' -Verbose -AcceptKey  -PathType File
Invoke-SSHCommand -SSHSession $session -Command 'rm -rf /tmp/output/*.*'
Remove-SSHSession $session -Verbose | Out-Null

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

There are a couple of errors in your code.
Try like this

$serv = "192.168.15.200"
$Username = 'root'
$pass = ConvertTo-SecureString -AsPlainText 'password@123' -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $pass
$session = New-SSHSession $serv -Credential $Cred -AcceptKey -ErrorAction Stop
$connected = $session.Connected
Invoke-SSHCommand -SSHSession $session -Command 'mkdir /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'chmod 755 /tmp/output'
Invoke-SSHCommand -SSHSession $session -Command 'cp /etc/passwd /tmp/output'
Get-SCPItem -ComputerName $serv -Credential $Cred -Destination 'D:\logs\' -Path '/tmp/output/passwd' -Verbose -AcceptKey  -PathType File
Invoke-SSHCommand -SSHSession $session -Command 'rm -rf /tmp/output/*.*'
Remove-SSHSession $session -Verbose | Out-Null

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Thank you very much....that worked 🙂

0 Kudos