Information Technology Reference
In-Depth Information
information. Let's now combine a few things we've discussed to show you how you can gener-
ate quick reports about your environment.
Since ESXi no longer stores logging information for any extended period of time, it is impor-
tant to have all of your ESXi hosts point their syslog data to an external location. Failure to do
so would mean that logs would be lost at reboot. How do you know which hosts are coni gured
and which are not? Using PowerCLI, you can i nd that information very quickly:
Get-VMhost | Get-VMHostSyslogServer |`
Export-CSV E:\Reports\Syslog.csv -NoTypeInformation
This one-liner gathers a collection of all of your ESXi hosts in inventory and then collects the
syslog server settings for each host. The i nal pipeline takes that syslog server information for
the hosts and exports it to a CSV i le. You may note that this script does not tell you which host
has what coni guration!
You can i x this by creating a parameter for the VMHost object in the pipeline. This is an
intermediate PowerShell technique but one we want to show you because it is very helpful with
cmdlets like Get-VMHostSyslogServer and Get-VMHostNTPServer:
Get-VMHost | Select Name, @{N=“SyslogServer“;E={$_ |Get-VMHostSyslogServer}} |`
Export-CSV E:\Reports\Syslog.csv -NoTypeInformation
Now that you have this information, what do you do if you have multiple ESXi hosts with the
incorrect syslog settings? Write a one-liner to update them of course!
Your First One-Liner: Configuration Change
PowerCLI is not just for reporting data on the environment. You also have the capability to mod-
ify the environment, assuming you have the appropriate privileges. In the preceding section,
you identii ed systems that did not have the correct syslog settings. To change them, you need
to identify the supporting cmdlet. In situations like this, where a Get- verb is used in a cmdlet,
it is common that a Set- verb is also available. In this instance, you'll want to use the Set-
VMHostSyslogServer cmdlet. Get-Help Set-VMHostSyslogServer -full tells you that you'll
need to specify the -SyslogServer parameter and perhaps the -SysLogServerPort parameter
if the syslog collector is listening on a specii c port. Assume in this scenario that you are send-
ing your logs to the VMware syslog collector on a server with IP address 192.168.0.100. Go ahead
and specify port 514:
Get-VMHost | Set-VMHostSyslogServer -SysLogServer`
192.168.0.100 -SysLogServerPort 514
You may have noticed that this one-liner does more than set the correct syslog server settings
on the systems that had the incorrect settings. It actually sets the settings on all of the VMHosts
collected with Get-VMHost. While this is not necessarily a problem, it could take a long time to
run in large environments. Let's assume that you wish to change only those that are not correct.
If you have a small environment, we recommend just running the previous one-liner to
update all systems with each pass. If, however, you have a large environment or a strong desire
to update only the incorrect settings, let's move forward. We're going to build on what we've
gone over previously and use some new PowerShell techniques. Let's identify the hosts with the
incorrect setting and update them with a single one-liner:
Get-VMHost | Select Name, @{N=“SyslogServer“;E={$_ |Get-VMHostSyslogServer}} |`
Search WWH ::




Custom Search