Scripting. Powershell, VMware, Windows, Active Directory & Exchange. All that kind of stuff…..
RSS icon Email icon Home icon
  • VCP-IaaS: Exam Resources

    Posted on May 20th, 2013 Jonathan Medd 1 comment

    I recently passed the VCP-IaaS exam and thought I would share the resources I used in case it is useful for anyone else. This is the exam which gives those already certified as VCP on vSphere, the VCP-Cloud certification.

    1) I took the VMware vCloud Director: Install, Configure, Manage [V5.1] course as my primary source. I enjoyed the course and felt it had a good mix of theory and hands on work. There are plenty of new networking concepts to grasp, so it was good to have many whiteboarded descriptions of them from a knowledgeable instructor. One thing to watch out for is that the course covers version 5.1, but the exam as of this date is still 1.5 – so you need to make sure you are aware of the key differences. Not many of significance for the exam, but the instructor did a good job of pointing them out. Why the exam is still testing 1.5 when 5.1 has been out since September 2012 I’m not sure!

    2) The instructor told us that the previous version of the course for version 1.5 contained vCenter Chargeback content, but it had been removed from this course. It’s covered in the exam though, so a bit annoying that it’s no longer in the course. However, I found a free self-paced online course, VMware vCenter Chargeback Manager Fundamentals [V2.5]. Having sat through this I can see why it was removed from the vCD training course (boring). Apart from some technical information needed on setting it up, it’s mostly aimed at beancounters, but useful for getting enough info you need for the exam.

    3) As always with any VMware exam make sure you read the blueprint and ensure you work through the mock exam. The blueprint is particularly helpful since it links to the correct versions of PDFs for the versions of vCD and vCenter Chargeback being tested on the exam.

    4) Whether you install vCD in your homelab or not the online Hands-On-Labs from VMware contains one lab for vCD and two for vShield which are well worth doing for additional practise.

    5) It’s always good to get some practise questions in to get you used to the typical kind of question you might be used in the exam. So in addition to the mock exam, I also used the vCD practise tests from Paul McSharry.

    6) Gregg Robertson has a useful list of VCP-IasS resources on his blog.

    5) One thing to get to grip with are the vCD networking naming terms, external, internal, isolate, direct, routed, various combinations of those terms etc and what they refer to. Between the training course, various blog sites and the exam, different terms often seem to be used to be used for the same concepts which led to some confusion for me during the exam.

    6) As of the date publishing this post there is a 50% off code for any VCP exam available from this page on the Pearson Vue site.

    In summary I felt that as with the vSphere VCP exam if you have enough hands-on-experience combined with a good understanding of the theory fundamentals, then you should be fine.

  • London VMUG – April 25th 2013

    Posted on April 16th, 2013 Jonathan Medd No comments

     

    There’s still time to register for the next London VMUG on April 25th 2013. As usual some excellent sessions are lined up – hope to see you there!

    image

  • Issue with PowerCLI: Not authenticated and session timeout

    Posted on March 15th, 2013 Jonathan Medd 1 comment

    A colleague of mine experienced this issue recently where after making a PowerCLI connection to a vCenter and instantly running a command such as Get-VM, he would be prompted by the error:

    
    Get-VM. Not authenticated. Possible cause of this error is that the connection was left unused for a while and session has timed out.
    
    

    Checking he was connected to a vCenter appeared to indicate that he was, i.e.

    
    $global:defaultVIServer
    
    

    returned a value. Seems like this may be an issue with PowerCLI 5.1 since other similar reports indicate reverting to 4.1 does not have the issue.

    We didn’t have that option, so in this instance took the recommendation to amend the PowerCLI timeout as follows, which seemed to help in our case:

    
    Set-PowerCLIConfiguration -WebOperationTimeoutSeconds -1
    
    
  • PowerCLI 101 at North East Bytes, Wed 20th March 2013

    Posted on February 21st, 2013 Jonathan Medd No comments

    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. VMware have been developing their own PowerShell-based management shell for some time – PowerCLI. In this session, Jonathan Medd, a Microsoft MVP for Windows PowerShell and VMware vEXPERT, will introduce PowerCLI and show you how to really take control of your virtual infrastructure.

  • Working with Custom Attributes in PowerCLI

    Posted on February 12th, 2013 Jonathan Medd No comments

    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.

    Having created the above, an additional column TestAttribute would be available in the vSphere client.

    and is also viewable on the VM summary page

    The additional TestAttribute column is also available in the vSphere web client:

    However, it is not available in the summary page of the VM (admittedly you can’t add them here via the GUI either, like you can in the C# client):

    In terms of accessing this data via PowerCLI there are a couple of ways to get at it:

    
    $VM | Get-Annotation
    
    $VM.CustomFields.Item("TestAttribute")
    
    

    These commands always seemed slightly strange in that there was no Get-CustomField cmdlet, Set-CustomField could create a new one and also to remove a custom attribute you needed to specify a single entity, selecting multiple would result in errors after the first one, e.g. Get-VM | Remove-CustomField would remove the custom field after the first VM, but then subsequently produce an error.

    
    $VM | Remove-CustomField -Name "TestAttribute"
    
    Get-Command *Field*
    
    

    So moving on, what is available now? Enter the Verb-Attribute cmdlets:

    
    Get-Command *Attribute*
    
    

    we now have a Get cmdlet, to access those already created.

    Now we must first create the custom attribute, then we can view created custom attributes with Get-CustomAttribute and set values with Set-Annotation

    
    New-CustomAttribute -TargetType "VirtualMachine" -Name "TestAttribute2"
    
    $VM | Set-Annotation -CustomAttribute "TestAttribute2" -Value "True"
    
    Get-CustomAttribute
    
    

    The data can be accessed the same way as before using PowerCLI

    
    $VM | Get-Annotation
    
    $VM.CustomFields.Item("TestAttribute")
    
    

    From a GUI perspective, the story is the same as before:

    We can now remove the custom attribute in a more typical PowerShell style:

    
    Get-CustomAttribute -Name "TestAttribute2" | Remove-CustomAttribute -Confirm:$false
    
    

    One thing to watch out for that tripped me up with this change was when I used New-CustomAttribute to create a custom attribute with multiple TargetTypes, e.g. Cluster,VirtualMachine. While this worked fine in my test environment using PowerCLI 5.1, when I ran the code in production to subsequently Set-Annotation on a new attribute it would fail with the issue detailed here. Turned out that the PowerCLI version in production was 5.0.

    
    Set-Annotation: The specified parameter 'CustomAttribute' expects a single value, but your name criteria 'TestAttribute' corresponds to multiple values
    
    

    It hasn’t been confirmed yet, but it looks like there is an issue with Set-Annotation in PowerCLI 5.0 that is fixed in 5.1.

  • Using PowerShell to access the vExpert.me URL Shortener

    Posted on December 6th, 2012 Jonathan Medd 2 comments

    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

    
    $vExpertMe = Invoke-RestMethod -Uri "http://vexpert.me/yourls-api.php?signature=secretcode&action=shorturl&format=json&url=http://www.jonathanmedd.net/2012/10/powershell-v3-new-in-operator.html"
    
    $vExpertMe
    
    

    and specifically to access the short URL:

    
    $vExpertMe.shorturl
    
    

    vExpertMe

    Note: Be careful of the password you choose if you go down the username and password route to query the YOURLS API. It appears to not like special characters in the password. Thanks to Darren for helping me troubleshoot that.

  • Finding Out Who You’re Not Following on vLaunchpad

    Posted on December 5th, 2012 Jonathan Medd No comments

    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.

    Line 1 pulls down the information from the web page.

    Line 2 breaks down the web page content until we get to the information we need.Firstly, we look at the Links property and filter those that include twitter content. Then for each one we split the URL on the / character and pick the username portion, e.g. from the below

    https://twitter.com/username

    we take username.

    Since some of the URLs are incomplete a few have a blank username so we use the regex pattern ^[a-z] to match anything with at least one letter. Finally, there were some multiple entries, so we pick out the unique ones and sort them into alphabetical order.

    $vlaunchpad = Invoke-WebRequest -Uri "http://planet.vsphere-land.com/"
    $twitterusers = $vlaunchpad.Links | where {$_.href -match 'twitter.com/'} |foreach {($_.href -split "/")[-1]} | where {$_ -match '^[a-z]'} | select -unique | sort
    

    vLaunchpad01

    So now we need to find out who we are already following and then compare the two.

    The PowerShell v3 cmdlet Invoke-RestMethod can be used to query the Twitter API. The documentation contains easy to use examples, for instance this one for finding those you are following (friends). So to find out who we are following we can make this query.

    $following = Invoke-RestMethod -Uri "https://api.twitter.com/1/friends/ids.json?cursor=-1&screen_name=jonathanmedd"
    
    $following
    
     

    vLaunchpad02

    As you can see though, this only returns the Twitter user id, not the name. Since I haven’t yet memorised all of the ids to those I am following, we need to convert them into names. The API documentation also includes a way to lookup these id values and convert them into names.One thing to watch out for is that the maximum number of ids that can be converted per query is 100, so if you are following more than that multiple queries will be required.

    Doug Finke has a post on his blog which bundles all of this up into one function, i.e. makes the two Twitter API queries per 100 users, but slightly differently it is focused on those who are following you. To amend this to find those you are following, simply change the line:

    $url = “$baseUrl/followers/ids.json?cursor=-1&screen_name=$($screenName)”

    to

    $url = “$baseUrl/friends/ids.json?cursor=-1&screen_name=$($screenName)”

    (although you may also wish to change all references from followers to friends to save any confusion)

    I also needed to make one other change, since by chance I was following a figure exactly divisible by 100, i.e. 600. Consequently, the last statement to make a query on the leftover failed with an error since there was nothing to query. So an updated friends based function now looks like this:

    function Get-TwitterFriend ($screenName) {
    
    $baseUrl = "https://api.twitter.com/1"
    function Get-Friend ($userIds) {
    $userIds = @($userIds) -join ","
    $url = "$baseUrl/users/lookup.json?user_id=$($userIds)&include_entities=true"
    (Invoke-RestMethod $url) |
    Select  name, screen_name, location
    }
    
    $url = "$baseUrl/friends/ids.json?cursor=-1&screen_name=$($screenName)"
    $friends = (Invoke-RestMethod $url).ids
    
    $blocks   = [Math]::Floor($friends.Count / 100)
    $leftover = $friends.Count % 100
    
    for($idx=0; $idx -lt $blocks; $idx+=1) {
    Get-Friend ($friends | select -First 100 -skip ($idx*100))
    }
    
    if ($leftover -ne 0){
    Get-Friend ($friends | select -First $leftOver -skip ($idx*100))
    }
    }
    
     

    We can now make the Twitter query we need and store the results for comparison:

    $TwitterFollowing = Get-TwitterFriend jonathanmedd
    
    $TwitterFollowing.Count
    
     

    vLaunchpad03

    All that is left is to compare $TwitterFollowing to $TwitterUsers , see who is missing, then go add those you wish to your followers list.

    $TwitterUsers | foreach {if ($_ -notin $TwitterFollowing.Screen_Name){$_}}
    
     
  • Automation Station at the UKVMUG 2012

    Posted on November 13th, 2012 Jonathan Medd No comments

    How do you provision, manage and decommission your (sprawling) infrastructure? Running around fighting fires while interesting project work falls by the wayside? Spending long evenings and weekends carrying out maintenance tasks while others are tweeting pictures of what fun they’re having in their spare time? Hiding from the bosses while they hunt you down to deploy a private cloud before Friday afternoon? Or even just figuring out what the heck infrastructure you have got and what underlying issues can you report on…..

    Maybe you should consider some automation within your environment. If you’re coming to this year’s UKVMUG on November 15th in Birmingham then come visit Alan Renouf, William Lam and myself at the Automation Station, part of the extensive range of additional community content available at this already great event.

    From provisioning / decommissioning physical and virtual servers, users, storage, networking and applications, through maintenance tasks, workflows and software testing, to what tools such as PowerShell, PowerCLI, vSphere CLI, Orchestrator, Python etc, you should or could use for different scenarios. We’d love to hear what automation you are already carrying out in your environment and have an opportunity to discuss what other things you could do.

    If you ask nicely we might even write some code for you to take away to carry out an automation task.

    Look forward to seeing you there and also highly encourage you check out the other community content available on the day (times subject to change, but we’ll be around all day :-) )

  • Install PowerCLI 5.1 in Windows 8

    Posted on November 13th, 2012 Jonathan Medd 1 comment

    I don’t believe that PowerCLI 5.1 is yet officially supported on Windows 8, however that’s where I wanted to run it. While carrying out the installation I hit this issue, i.e. .NET Framework 2.0 was not installed as a pre-requisite. This is because PowerShell 3.0 on Windows 8 uses .NET 4 and no longer has .NET 2.0 as a requirement.

     

    To install .NET Framework 2.0 in Windows 8 you need to turn on .NET Framework 3.5 as an optional feature, this will include .NET Framework 2.0. You can view the current status of this feature with PowerShell (note: the Online parameter means ‘take the action on the OS currently running on the local computer’):

    
    Get-WindowsOptionalFeature -FeatureName netfx3 -Online
    
    

     

    To enable .NET Framework 3.5, 3.0 and 2.0 run:

    
    Enable-WindowsOptionalFeature -FeatureName netfx3 -source D:\sources\sxs -Online
    
    

    where source is the location of the Windows 8 media.

     

    The state of this optional feature has been updated:

    
    Get-WindowsOptionalFeature -FeatureName netfx3 -Online
    
    

    You can now complete the PowerCLI install.

    It is now possible to take advantage of some the cool features in PowerShell 3.0, such as intellisense in the ISE console which includes the installed PowerCLI cmdlets:

  • UKVMUG 2012 – Agenda Published

    Posted on October 16th, 2012 Jonathan Medd No comments

    The agenda for this year’s UKVMUG has been published and looks tremendous. I know how much effort is put into organising this event and they look to have surpassed themselves this time. One great thing to highlight is the amount of community content there is amongst the published sessions, definitely putting the User back into a User Group.

    Watch out too for a further announcement about even more community content to be included as part of the day. I’ll be helping to provide some of this and suffice to say if you have an interest in automation then there’s going to be plenty of brain power on hand to help you out!

    Check out the current published content, you can register here and watch out for further community related announcements in the next couple of weeks…..