Category: PowerCLI

openssl.cfg for vcenter 5.0 (not 5.1)

for god sakes please use ver .9.8, if you use 1.0, the pfx wont work correctly and web services will be broke and you will be pulling your hair out.

Alan

add sans to openssl.cfg
# Extensions to add to a certificate request

basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName= @alt_names

[req]
req_extensions = v3_req
And in the v3_req section:

[ v3_req ]
subjectAltName = @alt_names

[alt_names]
DNS.1 = in2vc01
DNS.2 = in2vc01.corp.allscripts.com
IP.1 = 10.143.100.25

openssl.exe genrsa 1024 > rui.key

mine had to be 2048

openssl.exe genrsa 2048 > rui.key

openssl req -config openssl.cfg -new -key rui.key > rui.csr
openssl req -text -noout -in rui.csr
to verify

submit as 64 to cert, approve

openssl pkcs12 -export -in rui.crt -inkey rui.key -name in2vc01.corp.allscripts.com -passout pass:testpassword -out rui.pfx

[powershell]
# Get the hostsystem object for every host currently disconnected.
$VMhosts = Get-View -ViewType 'Hostsystem' `
-Property 'name' `
-Filter @{"Runtime.ConnectionState"="disconnected"}

Foreach ($VMhost in $VMhosts)
{
# Create a reconnect spec
$HostConnectSpec = New-Object VMware.Vim.HostConnectSpec
$HostConnectSpec.hostName = $VMhost.name
$HostConnectSpec.userName = 'root'
$HostConnectSpec.password = 'password'

# Reconnect the host
$taskMoRef = $VMhost.ReconnectHost_Task($HostConnectSpec,$null)

# optional, but i like to return a task object, that way I can
# easily integrate this into a pipeline later if need be.
Get-VIObjectByVIView -MORef $taskMoRef
}
[/powershell]

find vms with resource settings and set ram

[powershell]
$vms = Get-VM
foreach ($vm in $vms){
$vmre = $vm | Get-VMResourceConfiguration
if ($vmre.MemLimitMB -ne '-1'){
$rp = $vm | Get-VMResourceConfiguration
$rpvmmb = $rp.MemLimitMB
write-host $vm ", mem granted= " $vm.memorymb ", mem resources = " $rpvmmb
}}
[/powershell]

cooler one to only show when they don't match!

[powershell]
$vms = get-vm
foreach ($vm in $vms){
$vmre = $vm | Get-VMResourceConfiguration
if ($vmre.MemLimitMB -ne '-1'){
$rp = $vm | Get-VMResourceConfiguration
$rpvmmb = $rp.MemLimitMB
if ($vm.memorymb -ne $rpvmmb){
write-host $vm ", mem granted= " $vm.memorymb ", mem resources = " $rpvmmb
}}}
[/powershell]

VMlogix is a piece of shit.

vmlogix is a piece of shit, it crashes, explodes, and just does a bad job at life.

here is a script to detect with it explodes (and it will) by using the cpu values, if the rp is less then 9Ghz, it reboots it.

i have this a task to check every 30 mins for now, will probably change it to 15 when i feel like it

[powershell]#script to reboot labman if cpu useage is lower then expected.
#maybe.
connect-viserver atl-mis-vc01.eclipsys.lan
$uptimeweee = (get-stat -entity (get-vm atl-vmlm01) -stat sys.uptime.latest -maxsample 1 -realtime).Value
if ($uptimeweee -ge 1800){
$cpuuse = (Get-Stat -entity (Get-ResourcePool "LabManager-RP") -Stat cpu.usagemhz.average -MaxSamples 75 -realtime | Measure-Object Value -Average)
$cpuuse = $cpuuse.Average
Write-Host $cpuuse
if ($cpuuse -le 9500){
get-vapp LabManager | stop-vapp -Confirm:$false -ErrorAction:SilentlyContinue
sleep 30
get-vapp LabManager | start-vapp -Confirm:$false -ErrorAction:SilentlyContinue
}}
else {Write-Host "Not up long enough!"}
Disconnect-VIServer -Confirm:$false[/powershell]

Let's build some vm's

[powershell]

Connect-VIServer vcenter
$sr = Get-VM zTemplate2008R2SP1
$datastore = Get-Datastore ssd-nodeup
$num = 10
$vhost = get-vmhost esx-03*
while ($num -le 20){
$num2 = ($num-12)
Stop-VM 2008r2sp1-$num2 -Confirm:$false
$vm2 = New-VM -Name "2008r2sp1-$num" -VM $sr -Datastore $datastore -VMHost $vhost
Start-VM 2008r2sp1-$num
$num = ($num+1)
}
[/powershell]

Stage 4, no power :(

[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.alanrocks.com
#stage 4, we are fucked, and probably wont get power back. kill them all.
$hoeson = (get-vmhost | where {$_.Powerstate -eq "PoweredOn"})
$hoeson | Stop-VMHost -Confirm:$false -Force:$true
[/powershell]

Stage 3, Getting low on power....

Hell, where even going to stop a host now...
[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.alanrocks.com
#stage 3, now we are running leaning, and also fuck a host for good measure
$vmsilike = "dc1","vcenter","exchange2010","sql"
$vmson = (get-vm | where {$_.powerstate -eq "PoweredOn"})
$dievms = ($vmson -like $vmsilike)
foreach ($vmso in $vmson){if ($vmsilike -notcontains $vmso.Name){
# debug Write-Host $vmso.name "shut this bitch down"}}
$fvm = Get-VM $vmso
#findtoolsver
$toolver = (get-vm $fvm |% {get-View $_.id} | select @{Name="toolsver"; expression={$_.config.tools.toolsversion}})
if ($toolver.toolsver -gt 10000){$fvm | Stop-VM -Confirm:$false}
if ($toolver.toolsver -le 10000){$fvm | Shutdown-VMGuest -Confirm:$false}
}}
$ho = get-vmhost esx-02*
$clu = get-cluster -vmhost $ho
$task = $ho | Set-VMHost -Evacuate:$true -State "Maintenance" -RunAsync
Get-DrsRecommendation -Cluster $clu | where {$_.Reason -eq "Host is entering maintenance mode"} | Apply-DrsRecommendation
$host = Wait-Task $updateHostTask
$ho | Stop-VMHost -Confirm:$false -Force:$true
[/powershell]

Stage 2 Shutdown vm's we sorta care about

[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.alanrocks.com
#stage 2, shutdown or stop vm's not on this list
$vmsilike = "dc1","vcenter","dc2","files","exchange2010","sql","wordpress-win"
$vmson = (get-vm | where {$_.powerstate -eq "PoweredOn"})
$dievms = ($vmson -like $vmsilike)
foreach ($vmso in $vmson){if ($vmsilike -notcontains $vmso.Name){
# debug Write-Host $vmso.name "shut this bitch down"}}
$fvm = Get-VM $vmso
#findtoolsver
$toolver = (get-vm $fvm |% {get-View $_.id} | select @{Name="toolsver"; expression={$_.config.tools.toolsversion}})
if ($toolver.toolsver -gt 10000){$fvm | Stop-VM -Confirm:$false}
if ($toolver.toolsver -le 10000){$fvm | Shutdown-VMGuest -Confirm:$false}
}}
[/powershell]

Stage 1 shutdown for UPS, the vm's we don't care about

Stage 1, shutdown down vm's we don't care about
[powershell]
add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Connect-VIServer vcenter.alanrocks.com
#stage 1, shutdown or stop vm's not on this list
$vmsilike = "dc1","vcenter","VPNstuff","quickbooks","dc2","files","wordpress-win","exchange2010","sharepoint","sql"
$vmson = (get-vm | where {$_.powerstate -eq "PoweredOn"})
$dievms = ($vmson -like $vmsilike)
foreach ($vmso in $vmson){if ($vmsilike -notcontains $vmso.Name){
# debug Write-Host $vmso.name "shut this bitch down"}}
$fvm = Get-VM $vmso
#findtoolsver
$toolver = (get-vm $fvm |% {get-View $_.id} | select @{Name="toolsver"; expression={$_.config.tools.toolsversion}})
if ($toolver.toolsver -gt 10000){$fvm | Stop-VM -Confirm:$false}
if ($toolver.toolsver -le 10000){$fvm | Shutdown-VMGuest -Confirm:$false}
}}
[/powershell]

Find all ver and build hosts

[powershell]
Get-View -ViewType HostSystem | Select Name, @{N="Version";E={$_.Summary.Config.Product.FullName}}
[/powershell]

Where { $_.Version -match "ESXi"}

add for only esx

Reg all vm's in datastore

[powershell]
$esxhost= Get-VMHost anyhost
dir 'vmstores:\[email protected]\name\datastorename\*\*.vmx' |
% {New-VM -Host $esxhost -VMFilePath $_.DatastoreFullPath}
[/powershell]

WordPress Themes