Simons Roliga Kod

From Datateknik
Revision as of 14:23, 7 September 2020 by Siol0003 (Talk | contribs)

Jump to: navigation, search

This is a test

This text is not collapsible; but the next is collapsible and hidden by default:

PowerCLI för VMware (körs i Powershell!

För att skapa en mängd VLANS utan att sitta manuellt i Vcentret (obs PowerCLI är farligt!)

// 1. behövs för att köra vm-ware modulen i windows då den är "tredjepart"
Set-ExecutionPolicy remotesigned 

// 2. -Scope begränsar installation till inloggad användare
install-module -Name VMware.PowerCLI -Scope CurrentUser

// 3. Kommer att fråga om dina credentials, använd samma som gui inloggningen 
Connect-VIServer -server vcenter-b.cnap.hv.se

// 4. länk till object som är h6 hosten (till exempel)
$myVMHost = Get-VMHost -name esxi-h6.cnap.hv.se

!! VA RIKTIGT RIKTIGT SÄKER PÅ ATT DET ÄR HÄR DU VILL PILLA !!

// 5. länk till vswitch som skall pillas på
$vswitch = Get-VirtualSwitch -vmhost $myVMHost -name vSwitch1

// 6. Skapar VLAN med namn "VLAN20XX" och vlan id 20XX
for ($i=2004; $i -le 2038; $i++) {New-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" -VLanId $i}

// 7. tar bort portgroups "VLAN2037-VLAN2038" på vswitchen som definieras i steg >>5<<
// OBS! -confirm:$false stänger av en "are you sure, dummy" fråga. Är du inte säker, ta bort detta ur raden! OBS!
for ($i=2037; $i -le 2038; $i++) {Get-VirtualPortGroup -VirtualSwitch $vswitch -name "VLAN$i" | Remove-VirtualPortGroup -confirm:$false}

// Bryt kopplingen till vcentret
Disconnect-VIServer

Taget från virtuallymikebrown.com


Mass-radera VMs som matchar en sträng | Obs: anslut till rätt host också först (steg 1-4) ovan

Template:Lorem
$remove_vms = Read-Host -Prompt 'Input the server match string to remove from disk'
Write-Host "The entered string was: '$remove_vms'"
$select_confirm = Read-Host -Prompt 'Confirm your selection string (y/n)'

if($select_confirm -eq 'y') {
	 $VMs = Get-VM $remove_vms
	 foreach($VM in $VMs) {
	 	 Write-Host $VM
	 	 }
	 Write-Host "The listed VMs above will be permanently deleted from disk!"
	 Write-Host "Are you absolutely sure you want to do this?"
	 $nuclearoption = Read-Host -Prompt 'Type in "DELETE" to confirm this operation!'
	 if($nuclearoption -eq 'DELETE') {
	 	 Write-Host "Deleting..."
	 	 foreach($active in $VMs) {
	 	 	 if($active.Powerstate -eq "PoweredOn") {
	 			 Stop-VM -VM $active -Confirm:$false -RunAsync | Out-Null
	 			 Start-Sleep -Seconds 7 
	 			 }
	 		 }
	 	 foreach($delete in $VMs) {
	 			 Remove-VM -VM $delete -DeleteFromDisk -Confirm:$false -RunAsync | Out-Null 
	 			 }
	 	 }
	 }
Personal tools
Namespaces

Variants
Actions
Navigation
Tools