P2V scripting in Windows PowerShell..

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

ctrunk514Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BSonPoshCommented:
Perhaps I am confused, but you should always have two files... one is disk file and one is config file.
0
ctrunk514Author Commented:
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
BSonPoshCommented:
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
ctrunk514Author Commented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.