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
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
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
Thank you very much....that worked 🙂