Here are the possible values for the policy parameter on Set-VMHostService and their corresponding value in the VI client.
| Policy |
VI Client Value |
| automatic |
Start automatically if any ports are open… |
| on |
Start and stop with host |
| off |
Start and stop manually |
A lot of the script that I have been writing rely on new cmdlets or properties in the current release of PowerCLI. Telling people to upgrade before running the scripts has not been enough so I am going to do the smart thing and check that the appropriate version is running.
Here is the code to that I am using to do the validation.
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
| # By default this will check that the running version of PowerCLI is greater
# than or equal to the specified version and throw an exception if not.
# For an exact match specify the -exact parameter.
function Require-PowerCliVersion
{
param
(
[Int32]$build = $(throw "Require-PowerCliVersion: No build number specified."),
[switch]$exact # If true requires the exact build number to match.
)
$passed = $false
if (Get-Command Get-PowerCliVersion -ErrorAction SilentlyContinue)
{
$cliBuild = (Get-PowerCliVersion).Build
if ($exact)
{
if ($build -eq $cliBuild)
{
$passed = $true
}
}
elseif ($cliBuild -ge $build)
{
$passed = $true
}
}
if (!$passed)
{
throw "Require-PowerCliVersion: Minimum PowerCLI version requirement not met."
}
} |
Here is a short convenience script that will simulate a persistent login to a VMware host system when using the vCLI on Windows. Typically you have to specify a lot of parameters that include login information or a session file. With this method you just run the script and provide the hostname, username, and password for the connection.
After running this script you can run commands like “vicfg-mpath.pl –list” without additional parameters.
There is much that could be done to improve this script; this is just a quick and dirty version to make my life easier. If I improve it in the future I will post updates.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| #!/usr/bin/perl -w
use strict;
use warnings;
my $vcli_install_dir = "C:\\Program Files\\VMware\\VMware vSphere CLI\\bin";
chdir($vcli_install_dir) or die "Could not change to the vCLI directory: $vcli_install_dir";
print "Hostname:";
my $host_name = <STDIN>;
chomp($host_name);
$ENV{'VI_SERVER'} = $host_name;
my $session_file_name = $ENV{'TEMP'} . "\\vcli.session";
$ENV{'VI_SAVESESSIONFILE'} = $session_file_name;
system("..\\Perl\\apps\\session\\save_session.pl");
$ENV{'VI_SESSIONFILE'} = $session_file_name;
print "Spawning a logged in subshell. Type exit to end the session.\n";
system("cmd.exe");
# Remove the session file.
unlink($session_file_name); |
I have been confused by how to best use the -filter parameter on Get-View so I decided to dig around a little. The examples that are given always seem to be (semi)exact matches and I wanted to do an OR in my filter. Per the help this did not appear possible, but after some digging I found that it is possible for a single property at least.
Read more…
Here is a script that shows how to get access to the environment variables that VMware sets for a command step and perform some basic control flow using them.
Read more…
This is the first post in a series about using PowerShell to automate steps in a VMware Site Recovery Manager (SRM) workflow. I will be posting bits and pieces as I learn more and if everything works the way I would like I will post an overview of my testing and recovery procedure.
To use PowerShell in a Command Step of a recovery plan you will need to do the following:
Read more…
I am evaluating VMware Site Recovery Manager (SRM) and there are some things that I need to do in testing that I can not do in the base product. I am going to run some PowerShell to reconfigure the VMs and rename them. One of the first roadblocks is finding out which VMs are part of a particular recovery plan. Since the SRM API is limited I went into the database and dug around. Here is what I came up with. Let me know how it works for you. Especially if you have multiple protection groups. My configuration only has one.
Recommendations for better ways of doing this are appreciated.
USE [SRMDB01]
SELECT rp.plan_name, sv.shadowvmname AS shadowvm_name
FROM pdsr_shadowvm sv,
(SELECT sg.mo_id AS groupmoid, convert(varchar(255), g.string_val) AS shadowvmmoid
FROM pdsr_shadowgroup sg
LEFT OUTER JOIN g_string_array g
ON sg.vmmoids = g.seq_id) sg,
(SELECT rp.name AS plan_name, convert(varchar(255), g.string_val) AS shadowgroupmoid
FROM pdsr_recoveryprofile rp
LEFT OUTER JOIN g_string_array g
ON rp.shadowgroupmoids = g.seq_id) rp
WHERE sg.shadowvmmoid = sv.mo_id
AND rp.shadowgroupmoid = sg.groupmoid
AND rp.plan_name LIKE 'Recovery Plan 01'
September 16th, 2009
Eric
My new PRS600 reader from Sony was hung and I was getting pretty worried. I was using calibre on Linux and unplugged the device without unmounting. I would reset it and it would boot, but come to a blank version of the menu screen with 1fskin:/l/string… showing at the bottom. I tried a hard reset, but the device would not respond.
Here are the steps I did to resolve the issue.
- Push in the reset button in the bottom of the reader.
- Power on the device.
- Quickly plug the device into the computer (before it hangs again).
- Rename \database\cache\media.xml to media.xml.bak.
- Unmount and unplug the device to resume operation.
This may not solve every problem, but it worked for me.
There appears to be a discrepancy in the VMware documentation regarding the maximum number of vSwitches. The Configuration Maximums document states that the limit is 248. The configuration guide lists the maximum as 127 which is what it was in 3.5. I am not sure if I misunderstand what they mean by “Standard switches per host 248″. If you see the error of my ways let me know.
Here is some code that I used to see how many vSwitches I could put on a host. This will create 126 vSwitches, each with 8 usable ports, (I am assuming that vSwitch0 is already configured. Any attempts to add another one fail.
$vmhost = Get-VMhost <mytestHost>.local
1..126 | % {New-VirtualSwitch -VMHost $vmhost -Name vSwitch$_ -NumPorts 16}
A handy script to correct NTP settings on multiple hosts.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| #Usage: Get-VMHost | .\ConfigureNtpServer.ps1
BEGIN
{
$ntpServers = @("ntpserver01","ntpserver02")
$hostDateTimeConfig = New-Object Vmware.Vim.HostDateTimeConfig
$hostNtpConfig = New-Object VMware.Vim.HostNtpConfig
$hostDateTimeConfig.ntpConfig = $hostNtpConfig
$hostDateTimeConfig.ntpConfig.server = $ntpServers
}
PROCESS
{
$vmHost = $_
$vmHostView = Get-View $vmHost.ID
$dateTimeSystem = $vmHostView.ConfigManager.DateTimeSystem
$DateTimeSystemRef = Get-View $dateTimeSystem
$DateTimeSystemRef.updateDateTimeConfig($hostDateTimeConfig)
} |