Here is a script I wrote to install the VI Toolkit Extensions on my systems. The VITKE team decided to go with a cmd file in case PowerShell was not installed and I think that makes perfect sense. I am posting this code just in case it will be useful to someone else.
InstallVitkEextensions.ps1
I am working on a PowerShell script to replace the functionality of the logging daemon in VIMA and am making some progress. Check out the scripts/programs page for updates. I have posted the code out there for sending syslog messages from PowerShell. There are some third party tools for this but I wanted the learning experience and I am cheap.
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.")
I have added a new page that will be the central index to any scripts or programs that I develop. It is available on the front page menu bar and is creatively labeled Scripts/Programs.
I have started off with an updated version of my PowerShell ISE custom menu.
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.
I wanted to perform an action on all of the VMs on a particular host, but using my connection to Virtual Center instead of reconnecting directly to the host. I found something interesting.
This is wrong:
Get-VMhost esx1.local | Get-VM #Not what I expected.
This does not work as I expected. It gets all of the VMs in the cluster instead of just the ones registered with the host. My best guess is that this is because the host is not really a container object when in a cluster.
As a workaround you have to do something like this:
Get-VM | Where-Object {$_.Host.Name -eq ” esx1.local”}
To cut down on Get-VM processing time do:
Get-VMhost esx1.local | Get-VM | Where-Object {$_.Host.Name -eq “esx1.local”}
The first part of the pipeline still gets all of the VMs in the cluster, but this is better than all of the VMs in Virtual Center.
I thought I had a good solution and then a co-worker showed me a command line that he got from somewhere (sorry, don’t know where) that cut the processing time in half (Measure-Command is great).
(Get-VMhost esx1.local | Get-View).VM | % {$_ | Get-VIObjectByVIView}
Update 3/5/2009 — As Jeremy indicated in the comments, this is a more appropriate way to use Get-VIObjectByVIView:
(Get-VMhost esx1.local | Get-View).VM | Get-VIObjectByVIView
I had an issue where I ran a vendor provided install script and my kernel sound drivers were deleted. I recovered them just fine, but it had me wondering about how I could be sure that no other files were missing or corrupted.
After some searching online I found a reference to someone checking a package using dpkg’s md5sums. This and some poking around gave me what I needed.
cd /
sudo /usr/bin/md5sum -c /var/lib/dpkg/info/*.md5sums | tee /tmp/md5sum_results.txt
After that run is complete you can use grep to find things that are not OK and investigate them. If this is to be used for security validation the md5sums and related tools need to be stored on read only media.
Here is some code that I am working on for customizing the PowerShell ISE to do some things that I would like it to do.
Update 1/22/2009: After switching to a full WordPress install I don't have a problem uploading code files any more. Keep any eye on this page for any updates to the custom ISE menu. Feedback is welcomed.
#
# Add Run with arguments capability
#
$psise.CustomMenu.Submenus.Clear()
$__menu__ = $psise.CustomMenu.Submenus.Add("Run Script With Arguments", $null, $null)
$__menu__.SubMenus.Add("Run", {. $psise.CurrentOpenedFile.FullPath $__scriptargs__}, "Ctrl+Alt+R") | Out-Null
Read more…