This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find all of the VMs that have experienced ballooning in the last day | |
function ballooned? ($vm) { | |
$d = Get-Stat -memory -entity $vm -start (Get-Date).AddDays(-1) | | |
?{ $_.MetricId -eq 'mem.vmmemctl.average' } | | |
?{ $_.value -ne 0 } | |
return $d.count -ne 0 | |
} | |
connect-viserver -server virtualcenter -credential (Get-Credential (Get-Item env:username).value) | |
$vms = get-view -viewtype virtualmachine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create /etc/hosts style output of IPs - VM names | |
get-view -viewtype virtualmachine | ?{ $_.guest.ipaddress } | format-table -hideTableHeaders {$_.guest.ipaddress},name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VMware: set the advanced configuration option sched.mem.maxmemctl to zero to prevent ballooning | |
function deballoon ($vmname) { | |
# Set "sched.mem.maxmemctl" to 0 | |
$opt = new-object Vmware.Vim.OptionValue -Property @{ Key = "sched.mem.maxmemctl"; Value = 0 } | |
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec | |
$vmConfigSpec.extraconfig += $opt | |
# Use a filter to find a particular VM | |
$vm = get-view -viewtype "VirtualMachine" -filter @{ "Name" = $vmname } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find all VMs without the tools at the latest version/enabled | |
connect-viserver -server virtualcenter | |
get-view -viewtype "VirtualMachine" ` | |
| ?{ $_.runtime.powerstate -like 'poweredOn' } ` | |
| ?{ $_.guest.toolsstatus -notlike 'toolsok' } ` | |
| Sort-Object {$_.guest.toolsstatus} ` | |
| format-table name, {$_.guest.toolsstatus} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get-view -viewtype virtualmachine | %{ | |
$vm = $_.name | |
$vm.mac = @() | |
$_.Config.Hardware.Device | ?{ $_.MacAddress } | %{ $vm.mac += $_.MacAddress }; | |
$vm | |
} | format-table -wrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get-view -viewtype HostSystem | %{ | |
$_ | select-object @{ Name = "IP"; Expression = { $_.config.network.consolevnic | %{ $_.spec.ip.ipaddress } } },name | |
} | format-table -hidetableheaders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$vsphere = "my-vc" | |
$new_user = "newbie" | |
$new_user_passwd = "new_sekret" | |
$new_user_grp = "root" | |
$root_user = "root" | |
$root_passwd = "really_sekret" | |
# Get all of the ESX servers (connect using Windows credentials) | |
connect-viserver -server $vsphere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Clojure example for updating a DNS zone using dnsjava 2.1.1: | |
; http://www.xbill.org/dnsjava/ | |
; Tested against named 9.3.6 from Red Hat on RHEL5.4 | |
; Run using: java -cp clojure.jar:dnsjava-2.1.1.jar clojure.main dns-update.clj | |
(import '(org.xbill.DNS Update Name Type TSIG SimpleResolver)) | |
(defn replaceArec [resolver zone host ip ttl] | |
(let [update (Update. zone)] | |
(do | |
(. update replace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Return a list of vectors of hostname/ip address for VMware virtual machines from vCenter | |
; Export the environment variables: | |
; VI_USERNAME - your vCenter username | |
; VI_PASSWORD - your vCenter password | |
; VI_SERVER - the vCenter hostname/IP | |
; Invoke with the command line: | |
; java -cp clojure-1.2.0/clojure.jar:vijava2120100715.jar:dom4j-1.6.1.jar clojure.main hosts.clj | |
(import '(com.vmware.vim25.mo ServiceInstance InventoryNavigator)) | |
(def si (ServiceInstance. |
OlderNewer