Hi,
I need your help with a script that i am building.I need it to:`
# to find a VM and see if it is turned off or on.
# if it is off then turn it on and copy a folder with the content to the VM machine.
Regrades,
Michel Vaillancourt
You would put it before, Something like this:
$vmName = 'Target'
$folderName = 'C:\Folder'
Invoke-VMScript "del $folderName" -vm $vmName -HostCredential $HostCred -GuestCredential $GuestCred -ScriptType "bat"
Get-VM -Name $vmName | where{$_.PowerState -ne 'PoweredOn'} | Start-VM -Confirm:$false
sleep 30
Copy-VMGuestFile -LocalToGuest -Source $folderName -Destination $folderName -Confirm:$false
You might need to play with the command following Invoke-vmscript
$cmd = "del $folderName"
Invoke-VMScript "$cmd" -vm $vmName -HostCredential $HostCred -GuestCredential $GuestCred -ScriptType "bat"
You mean something like this.
Note that you can replace the sleep with a loop that checks if the guest OS is started up completely.
$vmName = 'Target'
$folderName = 'C:\Folder'
Get-VM -Name $vmName | where{$_.PowerState -ne 'PoweredOn'} | Start-VM -Confirm:$false
sleep 30
Copy-VMGuestFile -LocalToGuest -Source $folderName -Destination $folderName -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Thank's for your help. I'm getting the error that " WARNING: The guest OS for the virtual machine 'VM' is unknown. The operation may fail"
I have checked the name and it is VM..
Regards,
Michel v
The Destination parameter allows you to define the path inside the guest.
In the sample script I used the same path "C:\Folder" as the local source, but you can use a 2nd variable with another path.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
It works but i need it to delete the content of the old folder ( in the destination location) and replace it with the new one.
Michel v
how about adding:
Invoke-VMScript "del $myfolder" -vm $VM -HostCredential $HostCred -GuestCredential $GuestCred -ScriptType "bat"
You may have to adjust the variable names And add the force flag on the delete command.
were do i put the script that you wrote?before the privies script or after?
michel
You would put it before, Something like this:
$vmName = 'Target'
$folderName = 'C:\Folder'
Invoke-VMScript "del $folderName" -vm $vmName -HostCredential $HostCred -GuestCredential $GuestCred -ScriptType "bat"
Get-VM -Name $vmName | where{$_.PowerState -ne 'PoweredOn'} | Start-VM -Confirm:$false
sleep 30
Copy-VMGuestFile -LocalToGuest -Source $folderName -Destination $folderName -Confirm:$false
You might need to play with the command following Invoke-vmscript
$cmd = "del $folderName"
Invoke-VMScript "$cmd" -vm $vmName -HostCredential $HostCred -GuestCredential $GuestCred -ScriptType "bat"
ok,
And the resolute will be that the folder will copy it self from the target to the destination and the folder in the dest computer will be deleted and replaced with the new folder???
Regards,
Michel V
Yes, its a rough script and could probably use some testing and clean up, but you have all the parts above.
ok, thank you very much.
Do you know a way to get all of the alarms that esxi can publish? i need the full list
michel
I would open a new thread for that. It makes it easier for other folks to search for similar topics
ok.
Thank you.