Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Start stop action in powershell

$
0
0

Greetings

I am working in System Center Virtual Virtual Machine manager 2012 and I am utilizing the "view script" feature when doing certain actions in VMM.  For example, in the script below, I have copied the script for deploying a VM from the stored library to a location, then I create a clone of the image I just put in our environment, and then I ask it to put it back in the library after the clone is done.

My question has more to do with timing of the scripts.  I want the first piece to fire off, meaning deploy the image.  when the image it deployed, THEN I want the cloning of the image to take place.  When the clone is done, THEN I want the image I deployed to go back into the library.  I have copied all these scripts from VMM at the end of the process where you can hit the "view script" button.  I assumed I could just copy and paste them in there. 

How can I write the script where it waits until one piece is done and verified, and then move on?

Thanks!

# ------------------------------------------------------------------------------

# Deploy Virtual Machine Script

# ------------------------------------------------------------------------------

# Script generated on Thursday, January 23, 2014 2:50:11 PM by Virtual Machine Manager

#

# For additional help on cmdlet usage, type get-help <cmdlet name>

# ------------------------------------------------------------------------------

$vm = Get-SCVirtualMachine -ID "e7764114-4f09-4158-91ad-3b68ea377199" -Name "2008R2-2K8R2_PROG_STD"

$vmHost = Get-SCVMHost | where { $_.Name -eq "lv1qahv12.kfdqa.intra" }

$virtualNetworkAdapter = Get-SCVirtualNetworkAdapter -ID "09eee3a1-b21f-4850-82d6-08be2aafe4bc"

Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $virtualNetworkAdapter -VLanEnabled $false -NoLogicalNetwork -MACAddressType "Dynamic" -IPv4AddressType "Dynamic" -IPv6AddressType "Dynamic" -RunAsynchronously -JobGroup "c61807d6-cb6c-424c-a796-cb52704602aa"

Move-SCVirtualMachine -VM $vm -VMHost $vmHost -HighlyAvailable $false -UseLAN -RunAsynchronously -UseDiffDiskOptimization -JobGroup "c61807d6-cb6c-424c-a796-cb52704602aa" -Path "E:\Production\"

# ------------------------------------------------------------------------------

# Create Virtual Machine Wizard Script

# ------------------------------------------------------------------------------

# Script generated on Thursday, January 23, 2014 3:07:03 PM by Virtual Machine Manager

#

# For additional help on cmdlet usage, type get-help <cmdlet name>

# ------------------------------------------------------------------------------

New-SCVirtualScsiAdapter -VMMServer localhost -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f -AdapterID 255 -ShareVirtualScsiAdapter $false -ScsiControllerType DefaultTypeNoType

New-SCVirtualDVDDrive -VMMServer localhost -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f -Bus 1 -LUN 0

New-SCVirtualNetworkAdapter -VMMServer localhost -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f -Synthetic

Set-SCVirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 1 -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f

Set-SCVirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 2 -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f

Set-SCVirtualFloppyDrive -RunAsynchronously -VMMServer localhost -NoMedia -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f

$CPUType = Get-SCCPUType -VMMServer localhost | where {$_.Name -eq "3.60 GHz Xeon (2 MB L2 cache)"}

New-SCHardwareProfile -VMMServer localhost -CPUType $CPUType -Name "Profile57f0419f-70cf-4ff8-994a-a3ebcaca1b56" -Description "Profile used to create a VM/Template" -CPUCount 1 -MemoryMB 1024 -DynamicMemoryEnabled $false -MemoryWeight 5000 -VirtualVideoAdapterEnabled $false -CPUExpectedUtilizationPercent 20 -DiskIops 0 -CPUMaximumPercent 100 -CPUReserve 0 -NumaIsolationRequired $false -NetworkUtilizationMbps 0 -CPURelativeWeight 100 -HighlyAvailable $false -DRProtectionRequired $false -NumLock $false -BootOrder "CD", "IdeHardDrive", "PxeBoot", "Floppy" -CPULimitFunctionality $false -CPULimitForMigration $false -Generation 1 -JobGroup 34086e39-0ac0-4433-8221-8b116df55c5f

$VirtualNetworkAdapter = Get-SCVirtualNetworkAdapter -VMMServer localhost -Name "2K8R2_PROG_STD" -ID "09eee3a1-b21f-4850-82d6-08be2aafe4bc"

Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $VirtualNetworkAdapter -NoLogicalNetwork -VLanEnabled $false -NoConnection -NoPortClassification -JobGroup 3eea51ae-f7f5-45fc-8cc2-bbb7700dba8a

$VM = Get-SCVirtualMachine -VMMServer localhost -Name "2008R2-2K8R2_PROG_STD" -ID "e7764114-4f09-4158-91ad-3b68ea377199" | where {$_.VMHost.Name -eq "lv1qahv12.kfdqa.intra"}

$VMHost = Get-SCVMHost -VMMServer localhost | where {$_.Name -eq "lv1qahv12.kfdqa.intra"}

$HardwareProfile = Get-SCHardwareProfile -VMMServer localhost | where {$_.Name -eq "Profile57f0419f-70cf-4ff8-994a-a3ebcaca1b56"}

$OperatingSystem = Get-SCOperatingSystem -VMMServer localhost -ID "56a7486f-b989-4bd3-b38a-a6c4bb206f1b" | where {$_.Name -eq "64-bit edition of Windows Server 2008 R2 Standard"}

New-SCVirtualMachine -VM $VM -Name "2008R2-2K8R2_PROG_STD" -Description "2008R2-2K8R2_PROG_STD" -JobGroup 3eea51ae-f7f5-45fc-8cc2-bbb7700dba8a -UseDiffDiskOptimization -RunAsynchronously -Path "E:\Production\" -VMHost $VMHost -HardwareProfile $HardwareProfile -OperatingSystem $OperatingSystem -StartAction NeverAutoTurnOnVM -StopAction SaveVM

# ------------------------------------------------------------------------------

# Store Virtual Machine Wizard Script

# ------------------------------------------------------------------------------

# Script generated on Thursday, January 23, 2014 3:08:45 PM by Virtual Machine Manager

#

# For additional help on cmdlet usage, type get-help <cmdlet name>

# ------------------------------------------------------------------------------

$vm = Get-SCVirtualMachine -ID "e7764114-4f09-4158-91ad-3b68ea377199" -Name "2008R2-2K8R2_PROG_STD"

$libraryServer = Get-SCLibraryServer | where { $_.Name -eq "LV1QAVMMSERV01.KFDQA.INTRA" }

Save-SCVirtualMachine -VM $vm -LibraryServer $libraryServer -SharePath "\\LV1QAVMMSERV01.KFDQA.INTRA\MSSCVMMLibrary\VHDs" -UseLAN -RunAsynchronously


Ken Simonitis


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>