Post from January, 2010

Copy Con For PowerShell?

Wednesday, 27. January 2010 23:30

Hello again! This time I share a quick tip.

MS-DOS and cmd.exe shell power users remember for sure how easy it was to write a script (or any other text file) quickly from the command line without an editor. It was possible to copy the CON device (which stands for Console meaning keyboard/input and monitor/output as one device) to a file, for example COPY CON TEST.CMD. Once a COPY CON command has been invoked, it was possible to type whatever you want, even multiple lines were possible. When completed you could save the file and return to the prompt by pressing CTRL-Z (or F6) which would create ^Z (end of file) and then press Return.

In PowerShell there’s a similar approach as well but it doesn’t correspond one-to-one. The trick takes advantage of a single-quoted here-string to create a script:

PS C:\Users\Pit> @'
>> "Hello, $Env:USERNAME!"
>> "There are $((Get-ChildItem).Count) files and folders in this directory: $pwd"
>> '@ > .\test.ps1
>>
PS C:\Users\Pit> type .\test.ps1
"Hello, $Env:USERNAME!"
"There are $((Get-ChildItem).Count) files and folders in this directory: $pwd"
PS C:\Users\Pit>
PS C:\Users\Pit> .\test.ps1
Hello, Pit!
There are 15 files and folders in this directory: C:\Users\Pit
PS C:\Users\Pit>

Actually, Here-strings are used to embed more or less large text blocks inline in scripts. Here-strings start with “@” plus double- or single-quote followed by newline and end with newline, double- or single-quote followed by “@” .

Category:General, PowerShell | Comments (1) | Author: Frank-Peter

Virtualized browsers for free :)

Wednesday, 20. January 2010 1:48

If you want to test different browsers, but don’t want to install them locally, try Spoons. After installing small virtualization plugin, you can easily stream browser from spoons webpage – and it really works, surprisingly even with Internet Explorer 6.0 on Windows 7:

image

Spoons is based on XenoCode technology (which is very interesting by itself). They not only provide all major browsers, but also streamed games or video players.

Use it while you can :) Microsoft doesn’t like virtualized IEs around internet (remember Thindownload?), so once Spoons will become more popular, it will be closed (or at least applications will be removed).

Martin

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

LastPass for Applications

Monday, 18. January 2010 17:49

Very small announcement – just to let you know, my favorite password manager LastPass just released closed beta version that supports not only web pages, but also applications!

Very, very cool – I am betatesting at this moment and will let you know once it is released publicly. This was the only major feature I was still waiting for.

Martin

Category:Beta, Utilities | Comments (2) | Author: Martin Zugec

What is […[]] and when should I use it?

Monday, 18. January 2010 13:27

Maybe you noticed that some Powershell scripts are using [string[]] syntax – but what does it mean?

It is pretty simple – if you add [] after your type declaration ([int[]] or [boolean[]]), it means that value is array of objects of specified type.

If you simply use [array], then it is automatically translated to [object[]]:

@(1,2,3).GetType()

And when it is useful? Usually your functions don’t accept any type of input.

When you specify array of specific type, you can let Powershell decide if it can cast to object or not.

Consider following function:

Function X ([array]$Numbers) {…}

In this case, you can use X –Numbers 1,2,3, but also X –Numbers “Martin”, “Zugec”. And you code will probably fail later on.

If you use Function X([int[]]$Numbers) {…} and try to run X – Numbers “Martin”, you will get error message:

X : Cannot process argument transformation on parameter ‘Numbers’. Cannot conve
rt value "Martin" to type "System.Int32[]". Error: "Cannot convert value "Marti
n" to type "System.Int32". Error: "Input string was not in a correct format.""

Also, sometimes you cannot use [array] – especially in case of COM classes or WMI objects. One of examples is handling Citrix policies or load evaluator rules – in that case simply use [object[]] instead of [array].

Martin

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

Is cloud computing just a buzzword?

Monday, 18. January 2010 12:47

Is cloud computing really just a buzzword? We heard about it over and over – and every year predictions were that “now it will finally get of the ground, we promise”, but it never happened. What is the problem and why doesn’t it work??

In my opinion, problem is what people expects cloud is all about. If you ask people what is cloud computing, common answer is that “cloud computing allows you to take your application and move it somewhere to internet”.

This is something that won’t work. There are few simple reasons – companies don’t want to give up their data and move it somewhere outside and most companies don’t want to invest tons of money to rewrite their applications to run from internet. From this perspective, most famous cloud computing company is probably SalesForce. Well, I don’t fully agree with this definition – we can then say that Hotmail is also cloud computing (which is partially true).

From my perspective, cloud computing is moving your resources to internet and that’s a big difference. Idea that we will move everything to internet now is utopistic – that’s definitely not the way to go for serious companies.

So where is the future? In my opinion it lies with hybrid cloud computing.

Idea is very simple – it doesn’t make sense to make one big bang and simply move everything to internet – it will take ages before we will be (from technology and also trust perspective) to make that jump. Hybrid cloud computing means that you extend your current environment with cloud computing – you can start with 99% local and 1% cloud and then increase cloud ratio slowly if you are successful.

From hybrid cloud computing perspective, cloud is not mostly about applications, it’s mostly about resources – specifically servers.

Think about cloud computing as about environment consisting of virtual servers that are hosted on internet. In case you don’t use those servers, you don’t pay for them.

As we all know, also sentence “just rewrite all your applications to run from internet” doesn’t make too much sense – it’s even problem to rewrite business applications to NOT require IE 6.0. Well, in case you think about cloud computing as hosting platform, you can simply host there your terminal servers\XenApp servers and use your existing applications without any change.

Let me give you some examples.

Example 1 – disaster recovery

Usual requirement is to have disaster recovery plan – in case your environment is not available (for example natural disaster or terrorist attack), you should be capable of rebuilding your environment. Common approach is to have recovery site. But why not prepare that environment in cloud? Because cloud providers have great flexibility in amount of resources, they can guarantee in SLA that if needed, you will get 100 servers in 5 minutes. And of course – if you don’t use them, you don’t pay (or you pay just for virtual storage).

Example 2 – peak times

Consider scenario where you host application that is used by 10 people and 1 server is needed. What if that application got peak times (for example Christmas) when you need 50 servers? Sadly, typical approach is to buy those 50 servers and leave them up and running for rest of year, even though they are needed just for 1 month. Possible solution would be to host those servers in cloud and pay just 1/12 of price instead.

Example 3 – development and test environments

Everyone (especially in enterprise environments) should follow DTAP process (Development –> Test –> Acceptance –> Production). In real life, that’s not always the case and usual reason is lack of resources.

If you have 200 servers in production, test environment with 1 servers doesn’t fully prepare you for everything that could happen. Why not host your dev\test environment in cloud then? You will run it in case you need it and simply destroy it afterwards.

Example 4 – load balancing

Again, peak times – however this time unexpected ones. Part of your farm is destroyed or simply all users decided to try new release of their favorite application at once and performance of your servers is disaster. You could use load balancing and automatically build adequate number of servers in cloud to solve this.

Of course there are TONS of other examples how hybrid cloud computing can be useful. What is however very important (even though not required) is to have decent automation in place.

What is also VERY important to understand is that fact that with hybrid clouds, you don’t  need to host your data in the internet – you can use cloud as a frontend, however keep backend in your network.

If you are interested in hybrid cloud computing, feel free to look at available cloud providers – my favorite ones are GoGrid (though expensive) and FlexiScale (wait for FlexiScale 2.0 – many things will change!). If you would like to have workshop regarding cloud computing, feel free to contact me.

Martin

Category:Cloud computing, Virtualization | Comments (4) | Author: Martin Zugec

How can automation prevent IT Brain Drain

Monday, 18. January 2010 11:29

according to Wikipedia, brain drain is

is a large emigration of individuals with technical skills or knowledge, normally due to conflict, lack of opportunity, political instability, or health risks. Brain drain is usually regarded as an economic cost, since emigrants usually take with them the fraction of value of their training sponsored by the government.

Brain drain is very common in IT world – in general, we change companies every 3 years on average. Most companies try to fight with this using money (or benefits), however I don’t think it is best approach – there is always someone who is willing to pay more and that’s also reason why many internal employees becomes consultants or freelancers.

Based on my experiences, most IT guys are changing jobs because of money OR because they are too bored and are stuck with repetitive tasks. You can solve money problem – but what to do with boring jobs?

If you want to keep your IT brains in your company, good way to do so is to use their geek disadvantages – technical guys (well, at least good ones ;) ) love gadgets and loves to play. Building automated environment can be considered gadget in fact – it is a child of IT people and they take care of it and try to improve it over and over again. Automation is win-win situation – business can save money in many scenarios and it keeps IT guys happy about what they are doing.

Many people are afraid to automate – they think they could loose their jobs if they do so. In real life, it depends. If you are forced to automate by business, it’s usually done in order to save some money – to get rid of some employees. If YOU are the one that is pushing automation, story is different. If business knows that you need 2 days to install new server, they usually don’t know that you spend 1 hour installing new server and then rest of time improving your automation techniques (so next time you need half an hour to install server and got even more time for automation ;) ).

If you got solid automation strategy, sooner or later you end up with very robust solution and your people will take different approach to new problems (not discussing how, but discussing what would be the best way). The bigger and more advanced is your automation platform, the harder it is for you employees to leave and start from scratch somewhere else (especially in case they are not sure if they will be allowed to automate at new job and that maybe they will need to do all those boring repetitive tasks again).

Of course there are employees that doesn’t like automation at all and prefer to do everything manually, but be honest – are these people truly your biggest asset, or can you easily replace them if you need so?

Martin

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

Win7 Inside Out 5 – User Profile Service and UPHClean

Monday, 18. January 2010 10:55

In case you are administrator of either terminal servers or Citrix\XenApp servers, I am sure you know small life-saver called UPHClean – User Profile Hive Cleanup service. To explain problem that was there since Windows 2000 server:

it happens quite often that driver or application leaks registry\file handles (it opens handle, however doesn’t properly close it afterwards), therefore profile cannot be unloaded. This leads to situation where you have tons of similar profiles (MZugec, MZugec.000, MZugec.001…) and user experience is that their settings are reset to default (because new profile is loaded for them).

This was major pain with roaming profiles – because profile is not unloaded correctly, it cannot be copied back to central profile storage. Microsoft released utility called UPHClean to solve this situation – it was real life saver.

You can read KB from Microsoft with details about that problem: http://support.microsoft.com/kb/837115/en-us.

Now, some mythbusting :) Problem with profiles that were not unloaded is very common. Also very common recommendation from almost every SBC consultant is – always install UPHClean. However that’s not completely true.

Always install UPHClean if you are running Windows 2003 Server or OLDER operating system.

Since Windows Vista\2008 and newer, we have UPHClean 1.6 included in operating system – it is part of User Profile Service service.

There are however still issues that are not solved by ProfSvc as far as I know – for example hgfs.dat file from VMWare or hsperfdata from Sun (it’s not bug, it’s a feature :) ). I tried to contact Robin (creator of UPHClean) regarding his future plans, I will share those details with you once he replies.

Therefore, UPHClean is now officially dormant. There are many other changes to user profiles in Vista\7, I would like to share them with future (like using Win32_UserProfile to migrate profiles from workgroup to domain).

Do you still have issues with profiles not being unloaded at logoff? Share it with us in the comments.

Martin Zugec

Category:Internals, Mythbusting, Windows, Windows 7 | Comment (0) | Author: Martin Zugec

Low-Tech Encryption

Sunday, 10. January 2010 21:47

Hello again. This time I want to share a function to convert a plain-text string to an encoded string, ConvertTo-BlurredString, and a function to decode an encrypted string, ConvertFrom-BlurredString. The function names contain the wording “blurred” because my encryption method should be considered very, very basic. It is a real low-tech security solution. Please keep that in mind!

I wrote the algorithm a couple of years ago in order to save sensitive data like email addresses in HTML files or passwords in INI files in a more secure manner than in plain-text. At least the blurred string protects the data from reading out accidentally if a curious user is watching an admin at work.

Enough talk – here comes function #1, ConvertTo-BlurredString:

function ConvertTo-BlurredString {
    <#
    .SYNOPSIS
        Converts a plain-text string to a blurred string.
    .DESCRIPTION
        The ConvertTo-BlurredString function converts a plain-text string into
        a blurred string. It is used with ConvertFrom-BlurredString. The blurred
        string can be used in configuration files (.ini or .xml for example) in
        order to prevent unwanted readout by curious people.
        ConvertTo-BlurredString is a very basic security solution. Do not use it
        in high security scenarios.
    .EXAMPLE
        PS C:\> ConvertTo-BlurredString "Hello, World!"
        81:648:909:972:972:999:396:288:783:999:1026:972:900:297
        PS C:\>
    .EXAMPLE
        PS C:\> $blurred = "Hello, World!" | ConvertTo-BlurredString
        PS C:\> $blurred
        55696:16992:23836:25488:25488:26196:10384:7552:20532:26196:26904:25488:23600:7788
        PS C:\>
    #>
    param(
        [Parameter(ValueFromPipeline=$true)]
        [string]
        $String
    )
    begin {
        function BlurString ($String) {
            $Random = (New-Object System.Random).Next(2,254)
            $Key = [string]($Random * $Random)
            [string]$ReturnValue = $Key
            $String.ToCharArray() | ForEach-Object {
                $ReturnValue += ":" + ([Byte][Char]$_) * $Random
            }
            $ReturnValue
        }
    }
    process {
        if ($_) {
            $String = $_
        } elseif (!$String) {
            $String = $(Read-Host "Supply a value for the String parameter")
        }
        BlurString $String
    }
}

And now the according ConvertFrom function, ConvertFrom-BlurredString:

function ConvertFrom-BlurredString {
    <#
    .SYNOPSIS
        Converts a blurred string to a plain-text string.
    .DESCRIPTION
        The ConvertFrom-BlurredString function converts an blurred string into
        a plain-text string. It is used with ConvertTo-BlurredString.
    .EXAMPLE
        PS C:\> "81:648:909:972:972:999:396:288:783:999:1026:972:900:297" | ConvertFrom-BlurredString
        Hello, World!
        PS C:\>
    #>
    param(
        [Parameter(ValueFromPipeline=$true)]
    	[string]
        $BlurredString
    )
    begin {
        function UnravelString ($String) {
            $Chars = $String.Split(':')
            if ($Chars.Count -lt 2) {
                throw "'$String' is not blurred with ConvertTo-BlurredString"
            }
            [string]$ReturnValue = ""
            $Key = $Chars[0]
            foreach ($Char in $Chars[1..$Chars.Count]) {
                $ReturnValue += [Char][Byte]($Char/[math]::Sqrt($Key))
            }
            $ReturnValue
        }
    }
    process
    {
        if ($_) {
            $BlurredString = $_
        } elseif (!$BlurredString) {
            $BlurredString = $(Read-Host "Supply a value for the BlurredString parameter")
        }
        UnravelString $BlurredString
    }
}

How about using this functions as a module? Ok, just follow this steps:

Create a new directory in your Modules directory, for example “BlurStrings”.

Save the two functions in this folder.

Type the following commands in a text editor and save it as psm1 file, for example BlurStrings.psm1

. $psScriptRoot\ConvertTo-BlurredString.ps1
. $psScriptRoot\ConvertFrom-BlurredString.ps1

That’s all. The module is ready for use. If you enter

Get-Module –ListAvailable

you’ll see a new script module called BlurStrings (for example). If you need to use the module’s functions type

Import-Module BlurStrings

Now, the functions are ready to use. Hope you like it.

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

Easy to use help for PowerShell

Thursday, 7. January 2010 20:14

Today, I was asked by customer if there is some reference documentation about Powershell. I told him about Get-Help (which is extremely useful), however he wanted to have something displayed next to his console prompt for easy referencing (he was using Primal documentation).

Answer is in fact very, very simple (as almost everything in Posh once you know how to do it ;) )

Simply run Get-Help with –Online switch argument and new window will open with your help in it.

 

Martin

Category:PowerShell, Scripting, Windows PowerShell | Comments (2) | Author: Martin Zugec

Win7 Inside Out 4 – Libraries

Monday, 4. January 2010 21:20

As we all know, there are numerous ways how to quickly find and access your files\data and how to organize them.

Personally, I prefer usage of symbolic links\junctions together with regular cleanup of files. I prefer to use clean system and keep available just those files I really need – preferably I backup & forget about those I don’t use.

However, for normal user this is not very comfortable scenario and I fully understand that. Windows ecosystem is based on the fact that every user is different and prefers something else.

The way how data organization in Windows 7 is improved is by usage of libraries. Easiest way how to think about Library is that it is folder that will merge together multiple folders.

For example, you store some movies on your backup HDD (external, big and slow) and some on your local (internal, small and quick) HDD. You can merge both of these folder in library called Movies.

Also, there is another very important reason why libraries are important and you should use them even in case you will never access them. Indexing is based on libraries – therefore by configuring libraries you are telling Windows what kind of data you store in which folder. You can easily confirm this behavior – just add new folder to Libraries and then check indexing configuration – as you see, your folder is automatically added to indexing.

Technically, Libraries folder (not library itself) is shell folder. If you want to create it in other location (for example C:\), simply create folder called “Libraries.{031E4825-7B94-4dc3-B131-E946B44C8DD5}” anywhere on your computer. By default, this folder is located at %UserProfile%\AppData\Roaming\Microsoft\Windows\Libraries folder.

Library item itself however is special file with .library-ms extension. Content is regular XML file, as you can see below.

image

.library-ms file is just regular XML file

If you are interested in detailed MSDN documentation, see this article.

Important to mention is that if you want to add network share to your library, indexing must be enabled on remote share.

Martin Zugec

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