Accessing environment variables in PowerShell is easy, either:
dir env: to view all of them, or:
dir env:ProgramFiles to access a specific one. However, if you try that for the ProgramFiles(x86) environment variable you are greeted with the following error:
PS C:\\> dir env:ProgramFiles(x86) x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Wanted to let readers know that I have a 50% off promo code for an upcoming book from Richard Siddaway, ‘Learn Active Directory Management in a Month of Lunches’. It’s now available in Manning’s Early Access Program and I have a 50% of promo code which is valid until Feb 26, 2013 12 midnight EST. Use the code below when ordering:
learnadmau
Here’s the book abstract:
Active Directory is the heart of a Windows network, providing a centralized location for administration, security, and other core management functions.
OK, we all know it’s really called Noughts and Crosses, but to keep the search engines happy this is about Tic-Tac-Toe. While expanding my programming skills with another language I went through an exercise in this excellent book to create a Tic-Tac-Toe game. While at a loose end one evening, I thought I would take the logic, port it to PowerShell and add a few extra features. Nothing particularly clever in here, rather it’s an encouragement to break your code down into manageable functions.
While on my working sojourn up North my good friend and fellow PowerShell MVP Jonathan Noble asked me to present a PowerCLI 101 session for the North East Bytes User Group he helps to run. So on Wednesday 20th March you can join us for this event at Newcastle University, session abstract and sign up details are below:
NEBytes March 2013 - Power The World With Imagination PowerCLI 101 IT Pros are starting to come to grips with the idea of managing Microsoft products with PowerShell, but it’s not just Microsoft who are making use of the powerful automation capabilities on offer.
I recently had a need to create some custom attributes for Clusters and VMs in vCenter. Having previously done this a few times a while back in vCenter I fired up Set-CustomField in PowerCLI 5.1, but was greeted with the following message:
$VM | Set-CustomField -Name "TestAttribute" -Value "True" WARNING: Use Set-CustomAttribute cmdlet. WARNING: The 'Set-CustomField' cmdlet is deprecated. Use the 'Set-CustomAttribute' cmdlet instead. So it would work fine now, but going forward some of my code would be deprecated and potentially not work when PowerCLI was upgraded, so I looked for what the options now were, but before we do a quick review of what Set-CustomField gave you.
I recently had the opportunity to help out a good friend of mine, Nigel Boulton with a PowerShell issue he was experiencing. After some conversations and experimenting we came up with the following solution so we decided to cross-post the solution. Here’s the background from Nigel about why he had the issue in the first place and how we got around it:
Last week I had a requirement to perform a DNS lookup within a PowerShell script, using a DNS server other than the one that the machine in question was configured to use.
A colleague asked the question of whether a parameter function could belong to multiple parameter sets, but not all of them, say in Set A and B, but not C. So I tried a couple of things out, then checked the documentation to see what was actually possible.
It states
“Each parameter set must have a unique parameter that the Windows PowerShell runtime can use to expose the appropriate parameter set.
I was recently fortunate enough to be invited by fellow PowerShell MVP Jeffery Hicks to contribute to a new book published by Manning: PowerShell Deep Dives. The intention of this book is to follow in a tradition similar to that set by a group of SQL Server MVPs who have published two SQL Deep Dive books (1 and 2), with profits going to a nominated charity.
This PowerShell Deep Dive book features contributions from PowerShell MVPs, well known community contributors and Microsoft consultants.
Darren Wollard set up a very cool vExpert.me URL shortener for vExperts to use. I was curious whether this was available programmatically and turns out it is with a simple URL query. You either need to supply your username and password in the query (bad) or secret code (less bad– tip: find it on the tools page after logging in to the admin site) . Then the query from PowerShell is as simple as
The vLaunchpad site is a great resource for finding the best virtualisation blogs around and in the upcoming months will once again have a voting opportunity where you can register which ones you like best. It also handily includes the Twitter id of the blogger. I was curious to find an easy way to see who I wasn’t following on Twitter from the list.
By using the Invoke-WebRequest cmdlet it’s easy to pull down the Twitter links from the web page.