Hi,
Is there a way to specify password in the script for SCP to copy VMs from one ESXi
scp -r root@192.168.1.100:/vmfs/volumes/VNX_DS_Uni_Dev_Vol/app42/ .
I was able to replicate that timeout error you are getting.
The following seems to avoid that error and works for me.
Note that I use a timeout value in 2 locations!
'scp -rv -o ConnectTimeout=3600 /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .',
'ls -l /vmfs/volumes/FASLUN01'
$cmdSub = $lines -join ';'
$Credentials = Get-Credential
$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub -TimeOut 3600
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Which script are you talking about?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I dont have any script currently, I am manually performing the migration by logging into esxi host.
Is there a way to login to esxi host through script and execute this command
scp -r root@192.168.1.100:/vmfs/volumes/VNX_DS_Uni_Dev_Vol/app42/ .
Please help.
Sure, I would suggest to use the Posh-SSH module.
See also my Use Posh-SSH instead of PuTTY post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for your suggestion.
I have arrived to the below script
$esx = '192.168.10.10'
$Username = 'root'
$password = 'password'
$secpasswd = ConvertTo-SecureString -AsPlainText $password -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($Username, $secpasswd)
$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'
$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'
$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output
Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output
The above scripts runs and I get a prompt. the issue, how do I know the status of copy ?
please help...
Can't you just do an ls after the copy?
$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'
$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'
$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output
Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output
Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I think, copying is not happening. I made the below changes
$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'
$cmdSub2 = 'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'
$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'
$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output
$res
Output Error
scp: ambiguous target
If I understand your command correctly, you are copying a file on the same ESXi node between 2 directories.
Why do you use scp in that case?
Can't you just use 'cp'?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I tried even copying from different esxi host, still the same error
$cmdSub1 = 'cd /vmfs/volumes/FASLUN01'
$cmdSub2 = 'scp -r root@192.168.1.11:/vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'
$cmdSub3 = 'ls -l /vmfs/volumes/FASLUN02/ISO'
$session = New-SSHSession -ComputerName $esx -Credential $Credentials -AcceptKey
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub1 | select -ExpandProperty output
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub2 | select -ExpandProperty output
$res = Invoke-SSHCommand -SSHSession $session -Command $cmdSub3 | select -ExpandProperty output
$res
Error
scp: ambiguous target
Try like this.
Each new call to Invoke-SSHCommand is as if you opened a new terminal.
'scp -r /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .'
'ls -l /vmfs/volumes/FASLUN01'
$cmdSub = $lines -join ';'
$Credentials = Get-Credential
$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
The above works but I am getting the below error. Also how can get the status of the copy like 10% complete, 20% complete etc.....
Looks like you might be hitting a timeout.
Two things to try:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
I tried with the small file, it works without any issues but for bigger files still I am not able to see the status of the copy (% of copy complete)
Did you try specifying a TimeOut value?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
What did you specify as the TimeOut value?
My previous comment was incorrect, the default is 3600 seconds.
Does that copy take more than 1 hour?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
the default for 60, I changed to 3600, but still the same. I changed in two places from default 60 to 3600
How big is that ISO file?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ISO file is around 3 GB and takes around 7 - 8 mins to copy
even though, it says timeout error, copy is in progress at the backend and after sometime I see file was copied.
how can I avoid that timeout error ?
I was able to replicate that timeout error you are getting.
The following seems to avoid that error and works for me.
Note that I use a timeout value in 2 locations!
'scp -rv -o ConnectTimeout=3600 /vmfs/volumes/FASLUN02/ISO/en_windows_server_2012_r2_with_update_x64_dvd_6052708.iso .',
'ls -l /vmfs/volumes/FASLUN01'
$cmdSub = $lines -join ';'
$Credentials = Get-Credential
$session = New-SSHSession -ComputerName esx1.local.lab -Credential $Credentials -AcceptKey
Invoke-SSHCommand -SSHSession $session -Command $cmdSub -TimeOut 3600
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference