# Adding PS Snapin for SCVMM Add-PSSnapin -name Microsoft.SystemCenter.VirtualMachineManager Get-Vmmserver localhost # Pause Function function Pause ($Message="Press any key to continue..") { Write-Host -NoNewLine $Message $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") Write-Host "" } # Let's Create JobID $JobGroupId = [Guid]::NewGuid().ToString() # Sort VMs by Location # get-vmhost hyperv01.fabrikam.contoso.net | Get-VM | Get-VirtualHardDisk | sort-object Location | Format-List Name,Location # Pause # get-vmhost hyperv02.fabrikam.contoso.net | Get-VM | Get-VirtualHardDisk | sort-object Location | Format-List Name,Location # Pause # Let's Create Pop-up Menu [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | out-null # Variables $form = new-object system.windows.forms.form $buton = new-object system.windows.forms.button $girdi = new-object system.windows.forms.textbox $girdi2 = new-object system.windows.forms.textbox $girdi3 = new-object system.windows.forms.textbox $girdi4 = new-object system.windows.forms.textbox $girdi5 = new-object system.windows.forms.textbox $girdi6 = new-object system.windows.forms.textbox $girdi7 = new-object system.windows.forms.textbox $girdi8 = new-object system.windows.forms.textbox $bolum = new-object system.windows.forms.label $bolum2 = new-object system.windows.forms.label $bolum3 = new-object system.windows.forms.label $bolum4 = new-object system.windows.forms.label $bolum5 = new-object system.windows.forms.label $bolum6 = new-object system.windows.forms.label $bolum7 = new-object system.windows.forms.label $bolum8 = new-object system.windows.forms.label $bolum9 = new-object system.windows.forms.label # Bolum 9 $bolum9.text = "VDS DEPLOY SCRIPT" $bolum9.top = 10 $bolum9.left = 10 $bolum9.height = 20 $bolum9.width = 500 # Bolum 1 $bolum.text = "NAME" $bolum.top = 50 $bolum.left = 10 $bolum.height = 20 $bolum.width = 100 # Bolum 2 $bolum2.text = "SURNAME" $bolum2.top = 50 $bolum2.left = 225 $bolum2.height = 20 $bolum2.width = 100 # Bolum 3 $bolum3.text = "KNO" $bolum3.top = 125 $bolum3.left = 10 $bolum3.height = 20 $bolum3.width = 50 # Bolum 4 $bolum4.text = "HNO" $bolum4.top = 125 $bolum4.left = 115 $bolum4.height = 20 $bolum4.width = 50 # Bolum 5 $bolum5.text = "PASSWORD" $bolum5.top = 125 $bolum5.left = 225 $bolum5.height = 20 $bolum5.width = 150 # Bolum 6 $bolum6.text = "VDS TEMPLATE" $bolum6.top = 220 $bolum6.left = 10 $bolum6.height = 20 $bolum6.width = 200 # Bolum 7 $bolum7.text = "HYPERV NO" $bolum7.top = 220 $bolum7.left = 225 $bolum7.height = 20 $bolum7.width = 100 # Bolum 8 $bolum8.text = "HDD PART" $bolum8.top = 220 $bolum8.left = 350 $bolum8.height = 20 $bolum8.width = 75 # Girdi 1 - NAME $girdi.top = 70 $girdi.left = 10 $girdi.height = 50 $girdi.width = 200 # Girdi 2 - SURNAME $girdi2.top = 70 $girdi2.left = 225 $girdi2.height = 50 $girdi2.width = 200 # Girdi 3 - KNO $girdi3.top = 145 $girdi3.left = 10 $girdi3.height = 50 $girdi3.width = 50 # Girdi 4 - HNO $girdi4.top = 145 $girdi4.left = 115 $girdi4.height = 50 $girdi4.width = 50 # Girdi 5 - PASSWORD $girdi5.top = 145 $girdi5.left = 225 $girdi5.height = 50 $girdi5.width = 200 # Girdi 6 - TEMPLATE $girdi6.text = "W2K8WEB" $girdi6.top = 240 $girdi6.left = 10 $girdi6.height = 50 $girdi6.width = 200 # Girdi 7 - HYPERV NO $girdi7.text = "02" $girdi7.top = 240 $girdi7.left = 225 $girdi7.height = 50 $girdi7.width = 100 # Girdi 8 - HDD PART $girdi8.text = "E" $girdi8.top = 240 $girdi8.left = 350 $girdi8.height = 50 $girdi8.width = 75 # Buton $buton.text = "TAMAM" $buton.width = 120 $buton.height = 25 $buton.left = 160 $buton.top = 300 $buton.BackColor = 'BurlyWood' $buton_click = { $form.hide() } $buton.add_click($buton_click) # Formu hazirla $form.text = "Yusuf Ozturk - yusufozturk.info" $form.formborderstyle = 2 $form.height = 370 $form.width = 445 $form.BackColor = 'BlanchedAlmond' # Set Form Controls $form.controls.add($bolum) $form.controls.add($bolum2) $form.controls.add($bolum3) $form.controls.add($bolum4) $form.controls.add($bolum5) $form.controls.add($bolum6) $form.controls.add($bolum7) $form.controls.add($bolum8) $form.controls.add($bolum9) $form.controls.add($girdi) $form.controls.add($girdi2) $form.controls.add($girdi3) $form.controls.add($girdi4) $form.controls.add($girdi5) $form.controls.add($girdi6) $form.controls.add($girdi7) $form.controls.add($girdi8) $form.controls.add($buton) # Our Form $form.showdialog() | out-null # Final Variables $strFirstName = $girdi.text $strLastName = $girdi2.text $strKNO = $girdi3.text $strHNO = $girdi4.text $strPassword = $girdi5.text $strTemplate = $girdi6.text $strHyperv = 'hyperv' + $girdi7.text $strDiskPart = $girdi8.text + ':' Write-Host "Please confirm the informations below.." $strFirstName $strLastName $strKNO $strHNO $strPassword $strTemplate $strHyperv $strDiskPart Pause # All about Active Directory $strUserName = $strFirstName + ' ' + $strLastName dsadd user "CN=$strUserName, OU=Client, DC=fabrikam, DC=contoso, DC=net" -upn $strKNO@fabrikam.contoso.net -fn $strFirstName -ln $strLastName -samid $strKNO -display “$strUserName” -pwd $strPassword -desc “KNO: $strKNO” -disabled no # User Groups for VMM $VMPermission = 174 $hostGroup1 = Get-VMHostGroup -VMMServer localhost | where {$_.Path -eq "All Hosts"} $AddScope = $hostGroup1 $AddMember = @("FABRIKAM\$strKNO") Set-VMMUserRole -VMPermission $VMPermission -QuotaPoint 0 -AddScope $AddScope -VMMServer localhost -JobGroup $JobGroupId -AddMember $AddMember New-VMMUserRole -Name "KNO$strKNO" -Description "$strUserName" -UserRoleProfile SelfServiceUser -JobGroup $JobGroupId Write-Host "Please be sure about you didn't get error above.." Pause # VMM Deploy Set-VirtualFloppyDrive -RunAsynchronously -VMMServer localhost -NoMedia -JobGroup $JobGroupId Set-VirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 1 -JobGroup $JobGroupId Set-VirtualCOMPort -NoAttach -VMMServer localhost -GuestPort 2 -JobGroup $JobGroupId $CPUType = Get-CPUType -VMMServer localhost | where {$_.Name -eq "1.00 GHz Pentium III Xeon"} $Template = Get-Template -VMMServer localhost | where {$_.Name -eq "$strTemplate"} $VMHost = Get-VMHost -VMMServer localhost | where {$_.Name -eq "$strHyperv.fabrikam.contoso.net"} $HardwareProfile = Get-HardwareProfile -VMMServer localhost | where {$_.Name -eq "Student"} New-VM -Template $Template -Name "VM$strHNO" -Description "$strUserName" -VMHost $VMHost -Path "$strDiskPart\Hyper-V" -JobGroup $JobGroupId -RunAsynchronously -Owner "RHVMM\$strKNO" -HardwareProfile $HardwareProfile -RunAsSystem -StartAction TurnOnVMIfRunningWhenVSStopped -DelayStart 0 -StopAction SaveVM Write-Host "Please be sure about you didn't get error above.." Pause Write-Host "Please continue after finish of deploying.." Pause # Let's refresh the host Refresh-VMHost $strHyperv.fabrikam.contoso.net # Finish exit