Post from December, 2009

Cloud here, cloud there, cloud everywhere…

Wednesday, 30. December 2009 17:37

Maybe you attended my two presentations about cloud computing – first part was about “private” cloud (Live Mesh, SkyDrive, profiles stored on Internet, Ketarin…), second was about “business” cloud.

To summarize it, talking about private cloud, I don’t believe in “everything must go to web” scenarios, but I rather prefer hybrid cloud solutions – accessing online documents from your locally installed applications or using centrally stored configuration for your applications.

For business clouds, I again prefer hybrid solutions – even though I believe that small companies could already use virtual machine hosted on internet (like GoGrid of FlexiScale).

Core component of my private cloud is Live Mesh, but I was seeking for some time to alternative. My biggest complains are the fact that you cannot script Live Mesh and the fact that you cannot create special rules to handle conflicts (and for some folders, I got conflicts every few minutes). I was looking for alternative for some time, however I was not very successful.

Yesterday I installed again Gladinet – Gladinet approach is little bit different than other providers and I like that idea. Instead of building huge infrastructure, they simply provide “wrappers” around existing cloud storages.

If I should describe it to someone that doesn’t have any knowledge about cloud computing or storage, I would describe it as follows:

Gladinet allows you to map your internet-based storages as local folders

image

Gladinet drive

Among the list of supported storage providers you can find Google, Microsoft (both Azure and SkyDrive) or Amazon (S3).

image

List of supported providers is pretty impressive

image

Access your SkyDrive as regular drive

What I find as disadvantages? First of all, some people (Michal “Altair” Valasek) complained about the fact that it is not fully reliable – sometimes files doesn’t display correctly or they are not uploaded – I cannot confirm this (yet) however.

Second complain I got is about the fact that these folders doesn’t support symbolic links – error message returned by mklink is “The device does not support symbolic links.”  If this drive could support symbolic links, it would be much more useful and automated backup and integration with your local computer would be much better.

Third complain is about “Task manager”. Whatever you do (upload\delete…) will be queued to task manager and processed on background, which makes complete sense. I was however not able to find any option to disable automatic popup of task manager whenever you do something.

image

Task manager will popup whenever you perform any operation with mounted drive.

Just small hint, in case you would like to access Gladinet drive from elevated prompt. Your drive is mounted from \\127.0.0.1\Resources, so to remap it under elevated prompt, simply run Net Use X: \\127.0.0.1\Resources

Martin Zugec

Category:Cloud computing, Utilities | Comments (1) | Author: Martin Zugec

Win7 Inside Out – WinSxS

Wednesday, 30. December 2009 1:37

 

I promised some time ago that I will post 100 tips and tricks about Windows 7. Biggest problem I encountered was the fact that some tips were about how Windows7 works internally, while others could be described in 1 line (small tips). I decided that I will call these articles Win7 Inside Out. Part 1 is explaining some details about WinSxS, hope so you will find it interesting.

What is most common complain about Windows 7 or Windows Vista? Based on my investigation, it is mysterious WinSxS folder – most people complains that it is huge and instantly growing.

First, let me answer very simple question – is WinSxS really needed and is it clever solution, or just stupid workaround? My answer is very simple – YES, WinSxS is very clever solution and YES, we really need it in order to prevent DLL hell scenarios that we encountered in the past.

One small mistake Microsoft made while planning and designing SxS technology was that they didn’t think about popularity of upcoming netbooks (who could predict that?) and small but fast SSD drives. Currently, only real complain about WinSxS is the fact that you cannot change it’s location and it must reside on HDD where Windows is installed.

Why do we need WinSxS?

For non-programmers, it can be useful to describe functionality of libraries first. According to wikipedia, a library is a collection of subroutines or classes used to develop a software. To simplify it – if routine to copy one file consists of 50 lines of code, you don’t want to write it over and over again, but you rather create function called CopyFile and call this functions (so you use 1 line instead of 50). This is also very important from security perspective – if you discover bug in your routine, you need to fix it just once and it’s fixed for all programs that are using this routine.

In general, we recognize shared and private libraries – shared library needs to be on system just once, while private library needs to be added to every program that needs it. In past, to reduce size, we preferred mostly shared libraries, where multiple programs use single library:

image

Centralized approach

Well, that sounds like a brilliant idea – in theory. In real life, this just led to problem called DLL hell – to avoid damage to my brain, I won’t write details about it, I am sure you can find tons of complains on Google (915k results). So IT world turned other direction – from strictly centralized structure to decentralized structure:

image

Decentralized approach

On one hand, DLL hell issue was solved, or wasn’t it? Well, in fact we end up in situation that could be called DLL Hell 2 – it was hell to keep libraries up to date and from security perspective, it was disaster. Not talking about fact that applications were getting very huge in size – much bigger than our WinSxS folder. In my opinion however, it was still better than strictly centralized  structure.

There were many different workarounds and ideas – using .LOCAL files, manifests files, however WinSxS is truly solution worthy software giant like Microsoft.

So what is WinSxS about? It is central managed store for libraries in very clear structure.

 

Why is it so big?

First, let me tell you something – WinSxS is not that big at all. WinSxS is core of Windows operating system – and on my computer (Windows7), it’s 1.3 GB in size.

image

Hey, but doesn’t that dialog say that it is 5.76 GB? Answer is little bit more complicated – yes and no. WinSxS is using technology called hardlinks heavily – hardlink is according to Wikipedia

directory entry that associates a name with a file on a file system

You can have multiple hardlinks pointing to same place on file system – what it means is that you see multiple names (files), however they refer to same location.

Very common question is why then explorer doesn’t display real size? Answer is pretty simple – all hardlinks are equivalent (which is difference between hardlink and symbolic link), therefore you don’t have master (source) file and link (target) file. If you want to see details about your hardlinks, I can recommend you utility called Hardlink Scanner (both 32 bit and 64 bit) – there is no built-in tool in Windows to see hardlinks configuration.

image

Difference between hard links and symbolic links

As you can see in above picture – when we use symbolic links, we always have one “master” and one or multiple “slaves” (imagine that slave in .lnk file and master is .exe file), while with hardlinks all links are masters and changing any one of them will automatically change underlying data for all of them.

What it means when we talk about SxS is that most files in WinSxS folder are in fact stored somewhere else. Based on my experiments, almost 80% of files in WinSxS folder are just referencing to existing location (they are just hardlinks to other files). Talking about size of WinSxS folder, on my computer, 4.8 GB were simply linked files, while 1.3 GB were regular files. What is also very important to mention is that Windows is NOT only product that is using WinSxS – many other applications are also, so with bigger Windows folder, your Program Files size can be reduced. The real benefit of SxS technology is therefore pretty much hidden. Based on quick scan, I can see that there are 500 MB of hardlinks stored in my Program Files (30 GB in size).

Can I reduce it?

Well, that’s pretty hard question. Simple answer is no – mostly caused by the fact that removing files from WinSxS simply won’t give you more space (as long as there is any other hardlink pointing to that specific resource).

Uninstalling language packs

There is however very easy trick how you can reduce size of WinSxS folder – by removing language packs. If you have a look at structure of folders in WinSxS folder, you can see naming pattern there:
proc-arch_name_public-key-token_version_culture_hash

As you can see, part of folder name is culture. When you install Windows 7, you can see that multiple language packs are available as optional download:

image

Every one of them will add new resources to WinSxS folder – on average, it’s around 300 MB per language package. If you install all of them, it’s around 10 GB of data. So easiest way to reduce size of WinSxS is to simply uninstall additional language packs. Easiest way is to run lpksetup.exe – this will open dialog “Install or uninstall display languages”:

image

Be aware that it takes some time after uninstallation before WinSxS size is reduced!

My results:

EN + CZ:

Full size: 6.45 GB
Hard links: 4.98 GB
Normal files: 1.47 GB

EN only:

Full size: 6.18 GB
Hard links: 4.80 GB
Normal files: 1.37 GB

 

Deleting Windows Update cache

Second trick you can use is to delete Windows Update cache of manifest files. This file can be found in C:\Windows\WinSxS\ManifestCache folder – usually it’s not worth it, because it is smaller than 200 MB.

Uninstall some applications

As I explained before, some applications may use WinSxS. Usual recommendation is to uninstall some applications – but question is which ones? You can use Hardlink Scanner that was mentioned before to help you.

First find out which folders are biggest – you can use for example WinDirStat to find them.

Then you run Hardlink Scanner with /F switch against files in that directory. You will see something like this in output:

Scanning directories and files…..

Breakdown for "c:\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.1.7
600.16385_en-us_beafdf583b909e3f\1394.inf_loc"
=========================================================
  Unique ID:     100000000687e
  Hardlink count:            2
  Naive file size:       7,176 bytes
  Unique file size:      3,588 bytes
  Kind of file:         normal
  Filenames:
    \Windows\System32\DriverStore\en-US\1394.inf_loc
\Windows\winsxs\amd64_1394.inf.resources_31bf3856ad364e35_6.1.7600.16385
_en-us_beafdf583b909e3f\1394.inf_loc

 

Important part is Filenames – there you can see that this file is both the one in WinSxS and C:\Windows\System32\DriverStore\en-US\1394.inf_loc. That gives you an idea where is this component being used.

 

…to be continued -  this was first part of our article. This part describes WinSxS in more user-friendly way. In next part, we will go deeper into SxS – how it works, if you can move it to other disk and how can you work with it.

Category:Internals, Windows | Comments (7) | Author: Martin Zugec

Citrix Provisioning Services 5.1’s PowerShell Interface, Part III

Saturday, 19. December 2009 12:40

Hello again and welcome to the third part of my blog post series dealing with McliPSSnapIn – the PowerShell SnapIn to automate the Citrix Provisioning Services (PVS). Hope you enjoyed the first two parts and played with the McliPSSnapIn cmdlets meanwhile. This time you’ll learn how to handle the output of the Mcli-Get cmdlet meaning how to convert its structured text to an object (or an array of objects).

For example, suppose you want to display all vDisks sorted by size in descending order. By intuition, Mcli-Get DiskInfo and Sort-Object seem well-suited for this job get done.

PS C:\> Mcli-Get DiskInfo | Sort-Object diskSize -Descending

Worse luck! This will end up in a mess (which I don’t want to show here). As formerly mentioned, McliPSSnapIn’s cmdlets don’t deliver objects but rather text information just in the fashion of a legacy console utility. This is not much fun.

Since PowerShell supports the creation of custom objects you can convert Mcli-Get’s output to your own “homebrew” object, strictly speaking to a Device, Disk, Site, Store, Farm, whatever PVS object. Look at this working solution:

function PVS\Get-DiskInfo
{
	$record = $null
	$diskInfo = @()
	switch -regex (Mcli-Get DiskInfo)
	{
		"^Record\s#\d+$"
		{
			if ($record)
			{
				$diskInfo += $record
			}
			$record = New-Object System.Object
		}
		"^\s{2}(?<Name>\w+):\s(?<Value>.*)"
		{
			$record | Add-Member -Type NoteProperty -Name $Matches.Name -Value $Matches.Value
		}
	}
	if ($record)
	{
		$diskInfo += $record
	}
	return ,$diskInfo
}

Compared to the task to create an object and to assign property names with values to that object it is actually more challenging to parse the text-based information in order to identify the information related to each single object.

You’re not scared now, are you? ;-) Let’s take one thing at a time – according to Louis X divide et impera strategy.

First, let’s analyze the text returned by Mcli-Get DiskInfo on my test system:

PS C:\> Mcli-Get DiskInfo

Executing: Get DiskInfo
Get succeeded.  3 record(s) returned.
Record #1
  diskLocatorId: 5c3e5124-158b-44e7-891a-f600d1ebd072
  diskLocatorName: VDISK
  ...
  diskSize: 41940702720
  ...
  deviceCount: 0
  locked: 0

Record #2
  ...

Record #3
  ...

PS C:\> 

The cmdlet returned the “properties” of three vDisks. The text is structured nicely in order to support human readability:

  • The output begins with a short summary followed by an information block for each returned record (object).
  • Each information block is introduced with “Record #nnn” where nnn stands for a counter
  • Furthermore empty lines separate the information blocks from each other.
  • The lines that contain the actual data for the records (objects) are indented “name: value” pairs like “diskSize: 41940702720”

Based on this research findings you’re able design an algorithm as stated above to convert the cmdlet’s output to an array of objects.

The Power Of “switch -regex” Unveiled

Naturally you need to process the returned text data in a loop. At first glance it seems perfectly possible to use a foreach loop as follows:

foreach ($line in $(Mcli-Get DiskInfo))
{
	...
}

Inside each run it is important to distinguish between three cases:

  • A new information block begins (initiated by “Record #nnn”)
  • Information for the current record (object) in the form of “name: value
  • Superfluous information (as for instance the summary)

I consider this a classic case for a switch statement with the -regex option in order to identify a match with “Record #nnn” and a match with “name: value”.

foreach ($line in $(Mcli-Get DiskInfo))
{
	switch -regex ($line)
	{
		...
	}
}

You know what? switch is able to process a pipeline (an array of elements) itself, meaning you can forget foreach and let switch process Mcli-Get’s output directly:

switch -regex (Mcli-Get DiskInfo)
{
	...
}

According PowerShell’s help, the switch statement’s -regex option “indicates that the match clause, if a string, is treated as a regex string.” So, you need two regex strings, one to identify a “Record #nnn” line and one to identify a “name: value” pair. I will explain my regex statements below.

This regex string matches “Record #nnn”: ^Record\s#\d+$

Element Description
^ Matches the beginning characters
Record Matches “Record”
\s Matches any single white-space character
# Matches “#”
\d Matches any decimal digit
+ Matches repeating instances of the preceding characters
$ Matches the end characters

 

This regex string matches “name: value”: ^\s{2}(?<Name>\w+):\s(?<Value>.*)

Element Description
^ Matches the beginning characters
\s{2} Matches exactly two white-space characters
(?<Name>\w+) Matches any word character until the next non-word character and assign the result to $Matches.Value
: Matches “:”
\s Matches any single white-space characters
(?<Value>.*) Matches the rest of the line and assign the result to $Matches.Value

 

And what is $Matches? PowerShell places resulting matches automatically in the $Matches hashtable where $Matches[0] always holds the entire match. Furthermore, PowerShell allows to specify (optionally named) capture groups inside a regex string. These captures will be assigned to separate elements of the $Matches hashtable, either numbered or named. The example below shows what I’m trying to explain:

PS C:\> # Unnamed capture groups in a regex string
PS C:\> "  theName: the Value" -match "^\s{2}(\w+):\s(.*)"
True
PS C:\> $Matches

Name                           Value
----                           -----
2                              the Value
1                              theName
0                                theName: the Value

PS C:\> # Named capture groups in a regex string
PS C:\> "  theName: the Value" -match "^\s{2}(?<Name>\w+):\s(?<Value>.*)"
True
PS C:\> $Matches

Name                           Value
----                           -----
Value                          the Value
Name                           theName
0                                theName: the Value

PS C:\> $Matches.Name
theName
PC C:\> 

This is so cool! Did I already mention that I love PowerShell?

How To Avoid Flattening Of Arrays?

I need to tell you that the return value of the above-stated Get-DiskInfo function messed me around a while.

The function should always return an array regardless of the number of objects found by Mcli-Get. The problem I was running into was that the function didn’t returned an array when the object count was 1. Instead it returned the object directly.

In order to avoid that PowerShell unrolls or flattens the array when it would contain only one element I used the comma operator to force the function to return the array as is:

return ,$diskInfo

Ah, I’ve missed to show the Get-DiskInfo function in action:

PS C:\> # Is the function loaded?
PS C:\> test-path function:pvs\get-diskinfo
True
PS C:\> # assign the returning objects to $vdisks
PS C:\> $vdisks = pvs\get-diskinfo
PS C:\> # show disk sizes in gb
PS C:\> $vdisks | %{
>> "Disk Name: " + $_.diskLocatorName
>> "Disk Size: {0:N2}" -f ($_.diskSize/1gb)
>> }
>>
Disk Name: VDISK
Disk Size: 39.06
Disk Name: TestDisk
Disk Size: 10.00
Disk Name: VDISK2
Disk Size: 39.06
PS C:\> 

The Get-DiskInfo function is a very basic example for creating custom objects in PowerShell and therefore should considered to be a kick-start.

I hope it inspired you to dive deeper at Christmas time.

Category:Citrix, PowerShell | Comment (0) | Author: Frank-Peter

Best feature of Outlook 2010?

Tuesday, 8. December 2009 20:32

…at least for consultant is ability to connect to multiple exchange servers:

http://bink.nu/news/cool-outlook-2010-can-connect-up-to-15-exchange-organizations.aspx

Finally!!! :)

Martin

Category:Beta | Comment (0) | Author: Martin Zugec

Citrix Provisioning Services 5.1’s PowerShell Interface, Part II

Saturday, 5. December 2009 19:55

Welcome to the second part of my series of blog posts dealing with the PowerShell SnapIn called McliPSSnapIn that Citrix provides as an programming interface for the Citrix Provisioning Services (PVS).

The first part only covered the installation/registration of the SnapIn and furthermore it introduced a function called Test-PSSnapIn to add the SnapIn to the current PowerShell session (respectively to test if it could added successfully).

This time I want to point out more clearly how the McliPSSnapIn’s cmdlets vary from PowerShell standard. It’s just that the SnapIn has its own standard after all. A general approach to test if a given PVS object exists (like a vDisk, Device, or Collection) will top off part II.

McliPSSnapIn Standards

As mentioned in the prologue of part I, the cmdlets of McliPSSnapIn are not 100% PowerShell-compliant meaning that…

  • the cmdlet names don’t meet PowerShell’s “Verb-Noun” naming schema,
  • the cmdlet’s syntax doesn’t match with PowerShell’s standards, and
  • the cmdlets don’t return objects but arrays of pure text elements.

Instead, the McliPSSnapIn introduces its own standards – anything is better than nothing.

Cmdlet Naming

Overall there are only nine cmdlets or “command types” (Citrix-terminology):

Mcli-Add, Mcli-Delete, Mcli-Get, Mcli-Help, Mcli-Info, Mcli-Run, Mcli-RunWithReturn, Mcli-Set, and Mcli-SetList

You see, the cmdlet naming doesn’t follow PowerShell’s “Verb-Noun” principle but rather its own standard that is “Mcli-Verb” or “Mcli-Action” (according Citrix-terminology). Ah, did I already mention that Mcli stands for Management Command Line Interface?

Cmdlet Syntax

No worries! I won’t write down a boring command reference now. If you need a reference look at Citrix’ PVS Programmer’s Guide, and there’s the Mcli-Help cmdlet by the way. This section just outlines the things in common concerning the syntax of all Mcli cmdlets.

Mcli-Help left out, the general syntax may be summarized as follows:

Mcli-<Action> <ObjectType> <Arguments>

Basically, in terms of PowerShell standard you can take “Action” for “Verb” and “ObjectType” for “Noun” – not so bad after all.

Actions

Besides “Help” there are eight Actions:

Mcli-Add Add an object and return the object’s unique Id
Mcli-Delete Remove an object
Mcli-Get Get one or more objects and return according information as array of strings
Mcli-Info Get information about objects and return them as array of strings
Mcli-Run Run an action without return value
Mcli-RunWithReturn Run an action and return information as array of strings.
Mcli-Set Set property values for one or more objects without return value
Mcli-SetList Set a list of property values for an object without return value

ObjectTypes

Depending on the action there are more or less object types. To name but the most common only:

Collection, Device, DiskLocator, Server, Site, and Store

But as said before there are many more.

Arguments

There are four types of arguments indicated by “-f”, “-r”, “-p”, and “-s”:

-f Indicates a field (object property name) or a list of fields, separated by comma, to be returned.
-p Indicates a single or a comma-separated list of name=value pair parameters to identify an object.
-r Indicates a single or a comma-separated list of name=value pair records to be set on an object.
-s Indicates a field to sort on.

Syntax Examples

Some examples dealing with the Device object will certainly help to to clarify so much theory:

# Set the className to "Collection Class" in all of the Device objects of the Site
Mcli-Set Device -p collectionName=Collection, siteName=Site -r className="Collection Class"

# Add a Device
Mcli-Add Device -r deviceName=Device1, deviceMac=1a-2b-3c-4d-5e-6f, description="A description"

# And delete the Device
Mcli-Delete Device -p deviceName=Device1

# Get all Devices in the System you have access to
Mcli-Get Device

# Get a list of Devices in the Collection of Site. The only fields that will be returned
# are deviceName and description and the sort order will be deviceName decending.
# It is decending because of the - appended to the -s deviceName
Mcli-Get Device -p collectionName=Collection, siteName=Site -f deviceName,
description -s deviceName-

# Reboot all of the devices in the Collection of the Site
Mcli-Run Reboot -p collectionName=Collection, siteName=Site

# Return the count of Devices in the Collection of the Site
Mcli-Run DeviceCount -p collectionName=Collection, siteName=Site

# Return the count of Devices in the Collection of the Site
mcli-Run DeviceCount -p collectionName=Collection, siteName=Site

These samples are taken from the PVS Programmer’s Guide. I don’t know if they really work but it is good enough to show how the Mcli cmdlet syntax concept differs from PowerShell standards.

Cmdlet Return Values

The real annoyance about the Mcli SnapIn is the fact that their cmdlets return simple text, more precisely: arrays of strings. Practically the return values don’t differ from the return values of an external console utility like ipconfig.exe.

For example, it is well established that PowerShell’s most awesome feature is the Object Pipeline and it is a pity that you can’t use this extremely resourceful feature with the Mcli cmdlets. (Well, you can use the Object Pipeline in order to apply it to the string objects the cmdlets return though.)

Consequently, you need to inspect returning data using string operation methods like Substring() or Trim(). And PowerShell wouldn’t be PowerShell without its great Regular Expression support that helps tokenize strings to identify requested data (which is an easy task once you have played with regular expressions and understand how they’re working).

If you’re willing to put more effort in development time you can write your own PowerShell function library to encapsulate the Mcli cmdlet’s functionality completely and create your “homebrew” Collection, Device, Store, and Site objects with scripted methods. Maybe – it depends on your comments, folks! – I will provide some examples how to create your own object in a future part of this series about the PVS’ PowerShell SnapIn.

Hey, wake up! We’re back in example mode. ;-) The cmdlet Mcli-Add returns a unique Id of the object added. Look at this example output:

PS C:\> $rv = Mcli-Add Device -r siteName=Site, collectionName=Collection, deviceName=Device1, deviceMac=1a-2b-3c-4d-5e-6f
PS C:\> $rv

Executing: Add Device
Add succeeded.  resultId = 27ce63d7-c469-42ed-b828-82bad1d3c616
PS C:\> 

So, besides the interesting data (meaning the Add succeeded and the resultId) there’s virtually gross information. Now, let’s inspect the return value stored in the $rv variable….

PS C:\> $rv.Count
3
PS C:\> $rv[0]

PS C:\> $rv[1]
Executing: Add Device
PS C:\> $rv[2]
Add succeeded.  resultId = 27cd63d7-c469-24ed-b828-82bad1d3c616
PS C:\> 

You see, Mcli-Add didn’t return a Device object with all its properties and methods. Actually, it returned an array of three strings (the first is empty). Therefore, if you want to process the new Device – let’s say you need to set a property value (Citrix-terminology: record value) – you can’t just do it the way you might expect by typing this:

PS C:\> # Does not work!
PS C:\> $rv.description = "A description"
Property 'description' cannot be found on this object; make sure it exists and is settable.
At line:1 char:5
+ $rv.d <<<< escription = "A description"
PS C:\> 

No, instead you need to fire up another cmdlet, Mcli-Set, to apply the desired property value:

PS C:\> Mcli-Set Device -p deviceName=Device1 -r description="A description"

Executing: Set Device
Set succeeded.
PS C:\> 

So far, so good. The cmdlets work, but hopefully you’re getting the picture now why I consider the concept how Mcli works annoying. It’s not that ingenious PowerShell way, it’s just old school (meaning text based) scripting.

Test Object Existence

In this chapter I want to share a set of functions that test for existence of a given object, let’s say a Device.

For example the function PVS\Test-Device returns either “True” or “False” depending on the text information returned by Mcli-RunWithReturn. Let’s take a look at the function first:

function PVS\Test-Device ($Name)
{
	(Mcli-RunWithReturn Exists -p deviceName=$Name)[2] -match 1
}

Actually, the function returns “True” or “False” based on a regular expression comparison applied to the third line of Mcli-RunWithReturn’s text output. What matters is that the text of the third line matches the character “1”, meaning if there’s no “1” the given Device name doesn’t exist. Let’s have a look at the Mcli-RunWithReturn’s complete output:

PS C:\> #Test with an existing Device name
PS C:\> Mcli-RunWithReturn Exists -p deviceName=Device1

Executing: RunWithReturn Exists
RunWithReturn succeeded.  returnValue = 1
PS C:\> #Test with an non-existin Device name
PS C:\> Mcli-RunWithReturn Exists -p deviceName=Device2

Executing: RunWithReturn Exists
RunWithReturn succeeded.  returnValue = 0
PS C:\> 

You see, Mcli-RunWithReturn’s output differs only at the position where the cmdlet displays the return value. To prove that the function is working:

PS C:\> function PVS\Test-Device ($Name) {
>> (Mcli-RunWithReturn Exists -p deviceName=$Name)[2] -match 1
>> }
>>
PS C:\> #Test with an existing Device name
PS C:\> pvs\test-device Device1
True
PS C:\> #Test with a non-existing Device name
PS C:\> pvs\test-device Device2
False
PS C:\> 

Taking the PVS\Test-Device function as a reference it is easy to build more functions to test for example the existence of a Site, Store, or Disk:

function PVS\Test-Site ($Name)
{
	(Mcli-RunWithReturn Exists -p siteName=$Name)[2] -match 1
}

function PVS\Test-Store ($Name)
{
	(Mcli-RunWithReturn Exists -p storeName=$Name)[2] -match 1
}

function PVS\Test-Disk ($Name, $SiteName, $StoreName)
{
	(Mcli-RunWithReturn Exists -p diskLocatorName=$Name, siteName=$SiteName, storeName=$StoreName)[2] -match 1
}

The PVS\Test-Disk function needs some more parameters due to the fact that Mcli-RunWithReturn needs also the name of the Site and the Store to determine if a given Device name there exists.

You’ve reached the end of part II. Next part I will dive deeper into scripting tasks finally. So stay tuned and don’t miss the chance to write comments meanwhile…

Category:Citrix, PowerShell | Comment (0) | Author: Frank-Peter

Silverlight version of Bing Maps (Beta)

Thursday, 3. December 2009 11:44

My relation with Bing Maps was always love\hate. I love it because they are VERY good at experiments and brining new ideas – when I was watching i closely, I could see that new Google Maps features were introduced at Bing Maps\Live Maps few months before ;)

I hate it because they never finish what they started. And even thought they got great ideas, their maps are (at least in Europe) far from Google quality. However that’s different story :)

I wanted to share with you latest experiment by Bing Maps – silverlight based version of Bing Maps:

http://www.bing.com/maps/explore

image

Added automatic view switch

If you will feel that you don’t see many new features, click on following button:

image

Use map apps

I was very surprised when I saw how many Photosynth examples are around me (event in my building :) ). Also notice that you can see Twitter Maps – very nice idea :)

image

Available map apps

Martin

Category:Beta | Comment (0) | Author: Martin Zugec

Citrix Provisioning Services 5.1’s PowerShell Interface, Part I

Wednesday, 2. December 2009 21:02

With this post, I want to share some functions to automate Citrix Provisioning Services (PVS) 5.1. But let me tell a short story first…

Prologue

One of these days, I had to implement some PVS functionality into Solution4 at a customer. Only knowing by hearsay that a PowerShell programming interface or PowerShell SnapIn to automate PVS 5.1 exists, first I considered that task pretty easy. Some days later, during getting prepared for the job, the initial thrill of anticipation steadily changed into a feeling of disillusion. Why? I will tell you why.

To put it mildly, the PowerShell SnapIn for PVS 5.1 – baptized McliPSSnapIn – takes some getting used to, meaning it doesn’t follow any common PowerShell standards like the naming convention or the “syntax design” of cmdlets (to name the least worse first). The data returned from McliPSSnapIn’s cmdlets is – simple text! For example you won’t get an array of vDisk objects from Mcli-Get DiskLocator as one might expect with reason. Instead Mcli-Get returns an array of pure text lines without any deeper relation to the information. Thus you need to parse returning data just the way if they would coming from an external console utility – Whoop! Welcome to Split(), Substring(), Trim(), and their friends, not forgetting Regular Expressions that can make your day if you know how to use them.

Since McliPSSnapIn’s cmdlets are working I won’t claim that this SnapIn is load of crap. Nevertheless it’s annoying and I hope that Citrix will provide a PowerShell-compliant interface for PVS better late than sorry. (Yes, They Can! For example Citrix yet has done a good job on developing a PowerShell programming interface to automate Citrix XenApp – the Citrix XenApp Commands.)

First of all, you should get a copy of the Citrix Provisioning Services 5.1, 5.1 SP1 PowerShell Programmer’s Guide that is published in the Citrix Knowledge Center Article CTX121334. Don’t expect too much from this PDF document, it contains 150+ pages information though. The guide mainly consists of highly purified syntax help and much repeated information but it lacks substance like detailed descriptions. It is worth to use as command reference anyways.

Enough talk. (Did I already mention that I don’t like to talk?) Let’s have a closer look at McliPSSnapIn now.

Preparation

I believe you’re reading this article because you have Citrix Provisioning Services 5.1 (SP1) up and running and now need to realize some automation tasks in Windows PowerShell. Already mentioned previously, the essential requirement to automate Citrix PVS with PowerShell is the McliPSSnapIn PowerShell SnapIn.

McliPSSnapIn is a dll file and part of the Provisioning Services Console. Unsurprisingly you find the file in the PVS Console’s installation directory that is normally %ProgramFiles%\Citrix\Provisioning Services Console.

Before you can add the SnapIn to a PowerShell session with Add-PSSnapIn it needs first to be registered in PowerShell. This is a one-time task. As stated correctly in the PVS Programmer’s Guide, this can be done by running the .NET Framework’s utility InstallUtil.exe – see page 7, I don’t want to crib ;-)

How can I find out if the McliPSSnapIn is added to the current PowerShell session?

Several ways exist to check if a PowerShell SnapIn is added to the current PowerShell session. My way is a tiny little bit brute force since it simply tries to add the SnapIn without any previous steps:

function PVS\Test-PSSnapIn ($name = 'McliPSSnapIn')
{
	Add-PSSnapin -Name $name -ErrorAction SilentlyContinue
	[boolean] (Get-PSSnapin | Where-Object {$_.Name -eq $name})
}

First, my function tries to add the SnapIn while suppressing possible error messages by setting the according ErrorAction parameter value (SilentlyContinue). Indeed an error may occur due to the fact that either the SnapIn was added already or the SnapIn is not present on the system. Secondly the function tries to identify the given PSSnapIn using the Get-PSSnapIn cmdlet.

If the SnapIn is added (either just now or previously) the function will return “True”, apart from that it returns “False” if the SnapIn is not installed or registered. Beyond that (in case of return value “False”) you can dredge up the suppressed error message using the standard PowerShell variable $Error as follows:

if (PVS\Test-PSSnapIn)
{
	Write-Host "The SnapIn is loaded"
}
else
{
	Write-Host "The SnapIn is not loaded."
	Write-Host $Error[0].Exception
}

The $Error variable is PowerShell’s error stack. It saves the details of the errors that occurred recently (I don’t know how many). Each error is an array element, and the most recent error details can be found in the first element of the array, that is $Error[0]. The Exception property of the error object provides the error message.

Ok, this is end of the first part. I need to go to bed now ;-) More parts will follow soon. Good night and don’t miss the chance to write comments meanwhile…

Category:Citrix, PowerShell | Comment (0) | Author: Frank-Peter

Hidden property when using Powershell?

Tuesday, 1. December 2009 14:44

Today I run into pretty nasty bug in Powershell.

One of jobs that we support for S4Matic is used to automatically export\import any objects from (and to) SCCM. Packages are exported in universal format, so there are no internal IDs used and you can easily take these packages and import them to completely different environment.

To simplify process, we export all data to XML format and then import it if needed.

We support exclusion list to specify which properties you DON’T want to migrate. For example you don’t want to export\import information like creation date or last modification time.

At beginning, I used hashtable to define this. I wanted to move this to external configuration file – of course my first option would be XML format.

I was surprised when my scripts stopped working suddenly. After little bit of digging, I noticed that all scripts failed to export all “Name” properties.

Of course it makes sense if you think about it for a while – my approach won’t work if class where I store my data contains property with same name.

To my surprise, XmlElement DOESN’T contain property called Name. Of course psbase does:

 

$X.definition | gm | Where {$_.Name -eq "Name"}

$X.definition.psbase | gm | Where {$_.Name -eq"Name"}

   TypeName: System.Management.Automation.PSMemberSet

Name MemberType Definition
—- ———- ———-
Name Property   System.String Name {get;}

 

This is how I am testing for property:

$X.definition.name -is [object]

So even though Get-Member doesn’t display it in list of properties, Powershell is still using it – which is little bit scary, because that it can be really hard to predict how code will behave.

Martin

Category:Gotcha, PowerShell, Scripting, Windows PowerShell | Comment (0) | Author: Martin Zugec