Posts Tagged ‘PowerShell’

PowerShell and Proxy Auto Detect Problem

August 24, 2010

Just a quick one about this issue that has been plaguing me for ages. Like many people in corporate world, the browser on our corporate build is configured to point to an “automatic configuration script”. But perhaps unlike many corporates, the script at the place I work is f_huge_. And for some reason, this has introduced a problem for a particular .NET assembly that is associated with the System.Web namespace… the same namespace that is used by PowerShell when making web connections, such as when you invoke Connect-VIServer in PowerCLI.

The result is that powershell.exe starts chewing up memory like there’s no tomorrow… basically until your entire machine hangs. Lucky for me I don’t need to use PowerShell in anger on a daily basis, but this problem was enough for me to resort to running a vanilla XP VM whenever I needed to do stuff with PowerShell. But thankfully, someone took the initiative and looked into the problem with Microsoft, discovered the root cause, and a workaround. And so let it be known that I don’t get any credit for this post, but the person who should cannot be named for stupid corporate communications policy reasons.

And so here’s the workaround. Basically, you need to add the following to the powershell.exe.config file in the same directory as the powershell executable (both locations if you’re on an x64 machine – just create the file if it’s not there):

<?xml version="1.0" encoding="UTF-8"?>
   <proxy autoDetect="false"/>

Et voila! Problem solved. Not sure if any other .NET apps are affected by this, but any PowerShell scripts that directly invoke System.Web.Client (for example) will be – I have a script to grab UUIDs via the iLO interface of HP boxes, and got the same problem whenever I invoked that script. But not anymore, hooray!


Help Get PowerShell Into More VMware Products

March 2, 2009

From the VI Toolkit blog, Carter is running a poll over in the VI Toolkit community (login required in order to vote) to help VMware identify which products are in most need of PowerShellification. Of course, all VMware products are in need of PowerShell, but we understand they need to assign priorities to each of their products.

Personally, my vote is going to vCenter Orchestrator. Currently customised atomic units of a workflow can only be coded in JavaScript. All VMware admins / engineers / architects out there who are proficient in JavaScript please yell “JavaScript is not Java” now. Hmmm, I didn’t hear anything. And I have ninja hearing.

The reason I believe PowerShell support is so critical for vCenter Orchestrator is that the combination of automation and orchestration is where we all want to be. At least, it’s where the laziest of the lazy want to be, and booooy am I lazy. And by mere virtue of the fact that they visit this blog, I’m betting the 5000 or so unique visitors that come through here each month are lazy bastards too. Errr, extremely intelligent, good looking, lazy bastards.

For vCenter Orchestrator to be really successful, it needs a community to contribute these discreet workflow actions, as it would not be practical (or possible, probably) for VMware to ship every permutation of the basic VI operations with the vCenter Orchestrator product. And even if they did, there are bound to be people out there who know better ways to do things. Or at least _think_ they know better ways to do things ;).

So get over to the poll and have your say as to which VMware product will benefit from PowerShell next!

Shanklin Elevated From "Demigod" to "FullGod"… Film at 11.

January 28, 2009

After having a look around the new VI Toolkit release today, and the accompanying videos and documentation, I am convinced Carter will be hailed as a new God by VI admins the world over. I mean, even Boche has stated this release may be enough to move his lazy ass into finally learning the ways of the ‘Shell (I’ve been at him for ages about this, but alas he just ignores me).

I sooooo want to show the VI Java API some love (which was quietly updated to 1.0U1 only days ago), but with Windows Server 2008 R2 Core finally providing .net support, I’m more likely to wrap PowerShell scripts up in webservices for interop purposes than get dirty with Java (and that’s no reflection on the quality of what Steve Jin has done, which is top class).

Massive props to Carter and his team. With tools like this, I don’t give a fuck if vCenter or anything else becomes Linux based. Lets hope vCenter Orchestrator has native PowerShell support.

VI Toolkit 1.5 Released

January 28, 2009

The long awaited version 1.5 of the VI Toolkit has finally GA’ed, as Carter announced in the wee hours of this morning (2:30AM… I always wondered if Carter was a robot sent from the future, hopefuly not to destroy us all though).

Anyway ’nuff said, I’m gonna go get it now!

VI Toolkit and the PowerShell 2.0 Integrated Script Editor

January 2, 2009

Finally got a chance to install the PowerShell 2.0 CTP3, and have a look at the Integrated Script Editor (ISE). It has all the basic functionality you would expect from a scripting editor, including a very handy tab completion of cmdlets. It didn’t pick up the VI Toolkit cmdlets straight away for me though, so here’s how you’d enable that if you run into the same issue.

The ISE only picks up snapins that are loaded via one of the ‘AllHosts’ profiles, which is either ‘$pshome\profile.ps1’ (the AllUsers\AllHosts profile) or ‘$home\[My] Documents\WindowsPowerShell\profile.ps1’ (the CurrentUser\AllHosts profile). Until now I have stuck with using the CurrentUser\CurrentHost profile to customise my shell, which is in ‘$home\[My] Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1’. As a result, all the VI Toolkit cmdlets are available in any powershell session, however they aren’t available in the ISE.

So the fix was obviously simple – rename ‘$home\[My] Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1’ to ‘profile.ps1’. For anyone out there who doesn’t load the VI Toolkit with their normal powershell environment, simply add the following line…

add-PSSnapin VMware.VimAutomation.Core

… to $home\[My] Documents\WindowsPowerShell\profile.ps1 and you’re done!

VM Template for Citrix Provisioning Server

October 7, 2008

A rather odd bug with VirtualCenter is the inability to deploy VM’s with a SCSI controller but without a disk… even creating a template from a VM that has a SCSI controller but no disk results in a template with no SCSI controller (you then have to convert it to a VM, re-add the SCSI controller, then convert back to template. Only to find the SCSI controller stripped during the deploy from template. There’s 10 minutes of my life I’ll never get back).

If you’ve been reading this blog for any length of time you’ll know I’m not exactly a fan of Citrix XenServer, but Citrix Provisioning Server on the hand is _very_ cool (albeit prohibitively expensive and not without it’s drawbacks… another post maybe). For the uninitiated, Provisioning Server streams a disk via the network. But obviously the streamed disk needs to be access via a disk controller (duh!). Which is why I want to create a diskless template in the first place.

Before firing up the trusty PowerShellified version of Notepad2, i did a cursory search of the VI Toolkit forum to see if someone had done this already… and surprise surprise, Cool Hand LucD had done my work for me.

So yeh, now all I need to do is deploy my scsiless and diskless template with new-vm and call the function from LucD, and all is well in the world – big ups to LucD.

/me makes W shape with fingers on one hand while simultaneously pounding fist on chest with the other

VM Reconfiguration via the VI Toolkit for Windows

September 24, 2008

Reconfiguring VM’s via the API is something I’ve had to dabble in lately, due to some…. err.. “interesting” behaviour with deploying VM’s from templates. Such as the inability to deploy a VM from a template that has a SCSI controller but no disk – useful if using LUN based snapshots, where the .vmdk already exists and you want to move said vmdk into the same directory as the VM after it’s been created (and thus can’t use the -Diskpath option of New-VM as the path doesn’t exist yet). Or if you want to create VM’s for use with Citrix Provisioning server, which don’t require a local disk but do require a SCSI controller.

While this operation is uglier than I’d like it (most things that involve Get-View and specifications are uglier than I’d like them :-), I found this very good paper which explains the VI object model as applied to VM hardware reconfiguration _much_ better than the SDK documentation does.

Sure the examples are in Perl, but the theory is the same. Combine the document with a listing of all posts by Carter, LucD and halr9000 in the VI Toolkit for Windows community and there’s nothing you can’t do!

PowerAlarm Manager Script

August 31, 2008

Check out Shyam’s entry in the (now closed) VI Toolkit for Windows Scripting Contest, PowerAlarm Manager. It allows you to create alarms on any item in the VC inventory based on any perf metric. This is way cool – I’ve never quite understood why this functionality is not natively available. The Ready Time metric for example, is very useful as I’m sure anyone reading this blog knows. But we’ve never been able to create alarms based on it until now, thanks to Shyam!

So here’s hoping he gets a placing in the top 3, although with some very good entries in there it will be tough. We’ll post back any results as they come to hand, but in the meantime you should check it out and please report any bugs back to us!

PowerShell – Create X Number of VM's per Datastore

July 23, 2008

We all love the ‘shell, and the VI Toolkit for Windows even more. When i finish up with some other stuff, I’ll surely be pointing my C# skills at some cmdlets for that.

Anyway, there are a load of “create VM” scripts out there, I thought I’d show you one with a useful twist – create a certain number of sequentially numbered VM’s per datastore. For those new to the way of the ‘Shell, # is a comment (unlike batch or vbscript)

$esx = Get-VMHost -Name
$template = Get-Template -name TEMPLATE-NAME
$x = 1

#loop through all datastores on host
foreach ($d in Get-Datastore -vmhost $esx)

#check that it’s not a local datastore
if (!($ -match “:”))
#loop to create 10 VM’s per datastore
for ($i=$x; $i -lt ($x + 10); $i++)
#append a number to VM name
$vmname = “VM” + “$i”;
#create the VM from template
New-VM -Name $vmname -Template $template -Datastore $d -Host $esx
#set $x to the next number in sequence for the next datastore
$x = $i

There you have it. The only caveat is that the datastores don’t get returned by name so if you have sequentially numbered datatstores and want the VM numbers to match (ie VM1 – VM10 on ‘datastore 1’, VM11 – VM20 on ‘datastore 2’), you’ll need to pump the datastores into an array and -sort it first or something. I’ll leave the intrepid reader to handle that if required 🙂