Solved

P2V scripting in Windows PowerShell..

Posted on 2008-10-30
4
1,959 Views
Last Modified: 2012-08-13
P2V scripting

I have a P2V script which is attached that is working but when I try to start the VM using VMware Server Console the server just blue screens each time.

I am also posting the XML config file that I am using.

What I am trying to accomplish is to have my server P2Ved each night deleting the old P2V files as a backup.. also have the script send me an email telling me the start time and end time of the job. I am running this script in windows power shell.

The script works and finishs at 100% and I get the email just as I want. I end up with 2 files 1) servername.vmdk and 2) servername.vmx

And help? Is there a list of switches I can use with the P2VTool.exe? am I using the wrong switches? Im thinking the switch I am using is P2Ving the server for an ESX server and I need to P2V it for VMware Server Console not ESX.

THIS IS THE SCRIPT
 
    #Get the start time for the email message.
 
$startTime = get-date
 
&C:\Program Files (x86)\VMware\VMware Converter\P2VTool.exe --import --source 
C:\job\nsbb.xml
 
    #Get the finish time for the email message.
 
$finishTime = get-date
 
Move-Item C:\ConverterTemp\NSBB\* C:\Converter\NSBB force
 
Remove-Item C:\ConverterTemp\NSBB
 
    #Set up the email parameters and send the email.
 
 
$emailFrom = "Tad@******.com"
$emailTo = "Tad@******.com"
$subject = "VM Migration Task Complete..."
$body = "Your VM Migration started at: $startTime
 
Your VM Migration completed at: $finishTime
 
Please log into the Virtual Infrastructure Client to remove
any unnecessary hardware and ensure that the newly migrated
VM is on the correct network."
$smtpServer = "********"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
 
________________________________________________________________________
THIS IS THE XML CONFIG
 
<p2v uninstallAgentOnSuccess="0" version="2.2" xmlns="http://www.vmware.com/v2/sysimage/p2v" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/v2/sysimage/p2v p2vJob.xsd" xsi:type="P2VJob">
  <source>
    <liveSpec>
      <creds host="10.2.1.8" password="*****" port="0" username="NS\administrator"/>
    </liveSpec>
  </source>
  <dest>
    <hostedSpec path="\\10.2.1.6\ConverterTemp" password="******" username="NS\administrator" vmName="NSBB"/>
  </dest>
  <importParams clonePagefile="true" diskType="MONOLITHIC_SPARSE" keepIdentity="false" preallocateDisks="false" preserveDeviceBackingInfo="false" targetProductVersion="PRODUCT_WS_5X">
    <nicMappings preserveNicsInfo="false">
      <nicMapping network="Bridged"/>
    </nicMappings>
    <volumesToClone>
      <volumeCloneInfo newSize="12962482790" resize="true" volumeId="attVol={computer={8d56326b536472341b75b4f61b479869dbeb1967},1}"/>
    </volumesToClone>
  </importParams>
  <postProcessingParams installTools="false" powerOnVM="false">
    <reconfigParams/>
  </postProcessingParams>
  <jobState errorCode="0" id="8" startTime="2008-Oct-30 14:39:35" state="beingStopped" totalPercentComplete="18" type="import">
    <messages>
      <message id="Id_EstablishConnectionToAgent" type="Type_NewStep">
        <parameters>
          <parameter value="10.2.1.8"/>
        </parameters>
      </message>
      <message id="Id_CreateAndImport" type="Type_NewStep"/>
      <message id="Id_CreateConfigInfo" type="Type_Info"/>
      <message id="Id_CreateTargetVM" type="Type_Info"/>
      <message id="Id_FormatVolumeWithPath" type="Type_Info">
        <parameters>
          <parameter value="c:"/>
        </parameters>
      </message>
      <message id="Id_SnapshottingVolume" type="Type_Info"/>
      <message id="Id_CloningVolumeWithPath" type="Type_Info">
        <parameters>
          <parameter value="c:"/>
        </parameters>
      </message>
    </messages>
  </jobState>
</p2v>

Open in new window

0
Comment
Question by:ctrunk514
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22842791
Perhaps I am confused, but you should always have two files... one is disk file and one is config file.
0
 

Author Comment

by:ctrunk514
ID: 22843203
OK yes i have 2 file after the script runs, when i use the VMware Converter i can start the server and everthing works. but when i use the script the servre trys to start but blue screen..
0
 
LVL 18

Expert Comment

by:BSonPosh
ID: 22876070
I thought I would have time to poke around and figure this out, but alas I have not. I recommend you going to http://communities.vmware.com/community/developer/windows_toolkit and post your question there.
0
 

Accepted Solution

by:
ctrunk514 earned 0 total points
ID: 22881764
I found the answer!!!!
In my script i was missing "--postprocess" switch.. after using this the script runs and i can start my VM's

here is the script I am using I hope this helps other people trying to automate the P2V process and wants an email alert when the job is finished

Keep in mind this script needs to be run in Windows powershell 1.0, I use windows task scheduler with a bat file that calls this script.. each night I get e new P2V deleting the old one..

__________________________________________________________________________________

    #Get the start time for the email message.

$startTime = get-date

    #Run the p2vtool.exe utility to convert the VM from one ESX box to another.

&C:\Program Files (x86)\VMware\VMware Converter\P2VTool.exe --postprocess --import --source C:\job\nsbb.xml

    #Get the finish time for the email message.

$finishTime = get-date

Move-Item C:\ConverterTemp\NSBB\* C:\Converter\NSBB force

Remove-Item C:\ConverterTemp\NSBB

    #Set up the email parameters and send the email.


$emailFrom = "VM-P2V@********.com"
$emailTo = "Tad@********.com"
$subject = "VM Migration Task Complete for NSBB..."
$body = "Your VM Migration started at: $startTime

Your VM Migration completed at: $finishTime

Please log into the Virtual Infrastructure Client to ensure that the newly migrated
VM is on the correct network."
$smtpServer = "nsmail.ns.local"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linux VM 6 90
PowerCLi Script Email and Object Count Issues 13 47
XSLT Display Label Name 1 22
VMware 5.5:  OK to mount iSCSI LUN on multiple hosts? 1 30
When we have a dead host and we lose all connections to the ESXi, and we need to find a way to move all VMs from that dead ESXi host.
HOW TO: Install and Configure VMware vSphere Hypervisor 6.5 (ESXi 6.5), Step by Step Tutorial with screenshots. From Download, Checking Media, to Completed Installation.
Teach the user how to use configure the vCenter Server storage filters Open vSphere Web Client:  Navigate to vCenter Server Advanced Settings: Add the four vCenter Server storage filters: Review the advanced settings: Modify the values of the four v…
Teach the user how to use vSphere Update Manager to update the VMware Tools and virtual machine hardware version Open vSphere Client: Review manual processes for updating VMware Tools and virtual hardware versions: Create a new baseline group in vSp…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question