ForwardOrReverse

Latest Posts

Script for VM advanced settings

I created this one so I could easily apply multiple advanced settings to a list of VMs. The $advancedSettings array is easily modified to change what get configured.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Usage: <vmobject> | .\Configure-VmAdvancedSettings.ps1
# Examples: Get-VM myTestVM | .\Configure-VmAdvancedSettings.ps1
#           Get-Cluster myCluster | Get-VM | .\Configure-VmAdvancedSettings.ps1
 
BEGIN
{
    # The settings as an array of arrays.  ("key", "value)
    $advancedSettings = @( ("isolation.tools.copy.disable", "true"),
                           ("isolation.tools.paste.disable", "true"),
                           ("isolation.tools.setGUIOptions.enable", "false"),
                           ("log.rotateSize", "100000"),
                           ("log.keepOld", "10"),
                           ("isolation.tools.connectable.disable", "true"),
                           ("isolation.device.connectable.disable", "true"),
                           ("isolation.tools.diskWiper.disable", "true"),
                           ("isolation.tools.diskShrink.disable", "true")
                         )
    $keyIndex = 0
    $valueIndex = 1
}
 
PROCESS
{                      
    $vmView = Get-View $_.Id
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
 
    foreach ($setting in $advancedSettings)
    {
        $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
        $vmConfigSpec.extraconfig[-1].Key = $setting[$keyIndex]
        $vmConfigSpec.extraconfig[-1].Value = $setting[$valueIndex]
    }
    $vmView.ReconfigVM($vmConfigSpec)
}

Script to update tools in templates.

Here is a script that takes template objects and updates their VMware tools.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Usage: <template object(s)> | .\Upgrade-ToolsTemplate.ps1
# Example: Get-Template template1 | .\Upgrade-ToolsTemplate.ps1
#          Get-Datacenter corporate | Get-Template | .\Upgrade-ToolsTemplate.ps1
# Note: When getting template make sure to get the correct datacenter in case
#       there are duplicate names.
 
BEGIN
{
    $sleeptime = 60
}
 
PROCESS
{
    "Converting {0} to VM" -f $_.Name
    $vm = $_ | Set-Template -ToVM
 
    "Powering on the VM: {0}" -f $vm.Name
    $vm | Start-VM | Out-Null
 
    #TODO: Find a better way of doing this than just sleeping.  Perhaps poll 
    #      on tools status.
    "Sleeping for $sleeptime seconds"
    Start-Sleep -Seconds $sleeptime
 
    $vmview = Get-View $vm.ID
    "Existing Tools Version {0}" -f $vmview.config.tools.toolsVersion
 
    "Upgrading Tools"
    $vm | Update-Tools
 
    "Sleeping for $sleeptime seconds"
    Start-Sleep -Seconds $sleeptime
 
    $vmview = Get-View $vm.ID
    "New Tools Version {0}" -f $vmview.config.tools.toolsVersion
 
    "Powering off the VM: {0}" -f $vm.Name
    $vm | Stop-VM -confirm:$false | Out-Null
 
    "Converting to template"
    $vmview.MarkAsTemplate()
}

Added VMware Logforwarder to the Scripts/Programs Page

I have updated my Scripts/Programs page to include the bundle of scripts that I created when testing out forwarding options for logs that are not normally accessible via the service console syslog subsystem.

This set of scripts is functional, but ended at POC stage when I decided to go another route.  If there are any questions about them let me know, but they should not be used for production systems until more error checking added and testing is done.

Get-VIAllPrivileges

This is a good script to easily report on privileges and can easily be extended to audit against a known good list of expected roles/priveleges.

1
2
3
4
5
6
7
8
9
10
11
12
#Must already be connected to a viserver. This works on the default vi server.
$si = Get-View ServiceInstance
$am = Get-View ($si.Content.AuthorizationManager)
 
foreach ($role in $am.RoleList)
{
    foreach ($privilege in $role.Privilege)
    {
        $role| Select-Object RoleId, System, Name,
                             @{Name="Privilege"; Expression={$privilege}}
    }
}

PowerShell: Custom Objects with Method Parameters

I was not sure how to add parameters to custom object methods, but it is pretty simple.  Here is a simple example.

Function CustomObjectWithMethodParameter
{
    $CustomObject = New-Object PSObject
    $CustomObject | Add-Member -MemberType ScriptMethod -Name testParam -Value {
        param
        (
            [String]$parameter01 = $(throw "parameter01 must be specified.")
        )

        Write-Host "Parameter01 value: $parameter01"
    }

    $CustomObject
}

$myobj = CustomObjectWithMethodParameter
$myobj.testParam("Hello World.")

Plug for SAGE and USENIX

This is for the admins out there who have not heard of sage or Usenix or those that think that this is only for *nix people (Windows and VM admins).

I think that both of these groups are great and have memberships to both.  They focus on issues that are important to IT professionals and provide a forum for a professional system administrator to learn and grow.  Some topics have a *nix bias but beneath it all most of the current OSes are  based on the same principles.

http://www.sage.org/
http://www.usenix.org/

The conference proceedings are great.