VMware Cloud Community
xybal
Enthusiast
Enthusiast
Jump to solution

Command to relocate a VM to another DataStore

HI,

Is there a command to stop a VM, relocated it to another datastore and then restarted it on the new datastore (or in 2 commands).

Thx

Reply
0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can download PowerCLI from http://www.vmware.com/go/powercli. There you can also find the documentation. PowerCLI is a snapin for Microsoft Windows PowerShell that you can download from http://blogs.msdn.com/powershell/pages/download-windows-powershell.aspx if you don't have it allready. PowerShell is a scripting language and a shell like the DOS box. A very good book about PowerCLI is Hal Rottenberg's Managing VMware Infrastructure with Windows PowerShell TFM. And if you have any question about PowerCLI, you can ask them in the VMware PowerCLI Community.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

Reply
0 Kudos
11 Replies
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can do this in PowerCLI. Something like:

Connect-VIServer MyvCenterServer
Get-VM MyVM | Stop-VM | Move-VM -Datastore MyDatastore | Start-VM

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
xybal
Enthusiast
Enthusiast
Jump to solution

Hi,

Thank you for your answer.

I don't know how to use PowerCLI.

How to install it ? and how to use it ?

Have you any quick guide about it or any link ?

Thx

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

You can download PowerCLI from http://www.vmware.com/go/powercli. There you can also find the documentation. PowerCLI is a snapin for Microsoft Windows PowerShell that you can download from http://blogs.msdn.com/powershell/pages/download-windows-powershell.aspx if you don't have it allready. PowerShell is a scripting language and a shell like the DOS box. A very good book about PowerCLI is Hal Rottenberg's Managing VMware Infrastructure with Windows PowerShell TFM. And if you have any question about PowerCLI, you can ask them in the VMware PowerCLI Community.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
xybal
Enthusiast
Enthusiast
Jump to solution

When I type your command line it ask me for an answer (typ D for .., A for All etc)

Is it possible to automate my answer and not typing any character ?

Thx

Reply
0 Kudos
xybal
Enthusiast
Enthusiast
Jump to solution

When I type your command line it asks me for an answer.

Is it possible to automate my answer and not typing any chararcter ?

ThX

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

It is probably the Stop-VM cmdlet that asks for a confirmation. You can prevent that question by adding "-Confirm:$false" to the cmdlet. That changes the code into:

Connect-VIServer MyvCenterServer
Get-VM MyVM | Stop-VM -Confirm:$false | Move-VM -Datastore MyDatastore | Start-VM

Remember that you have to use the Connect-VIserver cmdlet only once in your session.

More information about the -Confirm parameter and other ways to prevent this question can be found at the Windows PowerShell Blog.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
xybal
Enthusiast
Enthusiast
Jump to solution

Thx for all your answers.

Now how can I launch these commands in a script ans how can I invoke this script ? (what is the syntax ?)

Thx

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership
Jump to solution

To run a PowerCLI script you have to put all the commands in a text file that you save with the extension .PS1. If you save the script as MyScript.PS1 in the current directory, you can run the script with:

.\MyScript.PS1

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos
xybal
Enthusiast
Enthusiast
Jump to solution

Ok thank you very much for your help.

I've already seen this information but I believed it was "psL" and not "ps1" extention and so it didn't work.

Now all is OK

Thx

Reply
0 Kudos
xybal
Enthusiast
Enthusiast
Jump to solution

I've put your command line in a file.ps1

Now I want to schedule this comand line.

To do that I use the "at" command with this syntax :

d:\tmp> at 14:40 .\file.ps1

Now I've got schedule this commands. When I test it at 14:41 for ie, the at command returns :

Error 1 Tomorrow 14:41 .\file.ps1

Can you help me with the correct syntax or is there something else ?

Thx

Reply
0 Kudos
xybal
Enthusiast
Enthusiast
Jump to solution

Is it possible to give login and password without typing it with command

<code>Connect-VIServer MyvCenterServer</code>What I want to do is automaticaly giving it my login / password.How can I do that please ?

Thx 

Reply
0 Kudos