Commit ba8bbd56 authored by Lonlone Lee's avatar Lonlone Lee

Initial pgvcenter scripts

parent 53f29759
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm
Connect-VIServer -Server pgvcenter.stanford.edu
Get-VM | Select Name,VMHost,PowerState | where { $_.PowerState -eq "PoweredOn" } | Export-Csv -Path C:\temp\PoweredOnVMsAndHosts.csv -NoTypeInformation -UseCulture
Disconnect-VIServer -Server pgvcenter.stanford.edu
\ No newline at end of file
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm
Connect-VIServer -Server pgvcenter.stanford.edu
Get-VM | Select Name,ProvisionedSpaceGB,UsedSpaceGB,NumCPU,CoresPerSocket,MemoryMB,Version,VMHost,PowerState | where { $_.PowerState -eq "PoweredOn" } | Export-Csv -Path C:\temp\PoweredOnVMSpecs.csv -NoTypeInformation -UseCulture
Disconnect-VIServer -Server pgvcenter.stanford.edu
\ No newline at end of file
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm
Connect-VIServer -Server pgvcenter.stanford.edu
Get-VM | Select Name,PowerState,
@{N="Tools Installed";E={$_.Guest.ToolsVersion -ne ""}},
@{N="Tools Status";E={$_.ExtensionData.Guest.ToolsStatus}},
@{N="Tools version";E={if($_.Guest.ToolsVersion -ne ""){$_.Guest.ToolsVersion}}} | where { $_.PowerState -eq "PoweredOn" } | Export-Csv -Path C:\temp\VMWareToolsStatus.csv -NoTypeInformation -UseCulture
Disconnect-VIServer -Server pgvcenter.stanford.edu
\ No newline at end of file
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm
Connect-VIServer -Server pgvcenter.stanford.edu
Get-VM | Get-Snapshot | Select vm,name,description,created,sizegb | Export-Csv -Path C:\temp\GetSnapshots.csv -NoTypeInformation -UseCulture
Disconnect-VIServer -Server pgvcenter.stanford.edu
\ No newline at end of file
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm
###############
# These are the values you should get from your webform
#
$snapMemory = $false
$snapQuiesce = $true
$emailAddr = 'postgrads-sysadm@lists.stanford.edu'
$fileName = 'C:\Temp\snapshotScheduler.csv'
$vcName = 'pgvcenter.stanford.edu'
###############
Connect-VIServer -Server $vcName
Import-Csv -Path $fileName -UseCulture | %{
$dateString = $_.SnapTime,$_.SnapDate -join ' '
$snapTime = Get-Date $dateString
$snapName = $_.SnapName
$snapDescription = $_.SnapDescription
$VMName = $_.VMName
$Description = $_.SnapDescription
Write-Host "VMName: $VMName"
$vm = Get-VM -Name $VMName
$si = Get-View ServiceInstance
$scheduledTaskManager = Get-View $si.Content.ScheduledTaskManager
$spec = New-Object VMware.Vim.ScheduledTaskSpec
$spec.Name = "Snapshot",$vm.Name -join ' '
$spec.Description = $Description
$spec.Enabled = $true
$spec.Notification = $emailAddr
$spec.Scheduler = New-Object VMware.Vim.OnceTaskScheduler
$spec.Scheduler.runat = $snapTime
$spec.Action = New-Object VMware.Vim.MethodAction
$spec.Action.Name = "CreateSnapshot_Task"
@($snapName,$snapDescription,$snapMemory,$snapQuiesce) | %{
$arg = New-Object VMware.Vim.MethodActionArgument
$arg.Value = $_
$spec.Action.Argument += $arg
}
$scheduledTaskManager.CreateObjectScheduledTask($vm.ExtensionData.MoRef, $spec)
}
Disconnect-VIServer -Server $vcName
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment