Showing posts with label sys admin. Show all posts
Showing posts with label sys admin. Show all posts

Friday, March 06, 2009

Essential Windows PowerShell Commandlets

Previously, we learned the basic commands: help and gal. I suppose now it's time to properly refer to these "commands" as commandlets or cmdlets following PowerShell's own set of terminologies. But just to note that whenever both commands and commandlets, I use them interchangeably for the same semantic meaning. Call me stubborn. Call it bad habit. But they really are all just commands to me. In any case, although I think of all of the commandlets simply as commands, we should still mentally note at the back of our mind that for "data-typing" purposes, PowerShell truly types these items or commands as Cmdlet.

Our first essential command after learning the basics is Get-Command

Get-Command

Get-Command outputs all of the available commands in PowerShell in a clean PowerShell installation. These are the commands that we really will use as the building blocks for writing PowerShell scripts. Through a process of trial and errors, let us try to see if we can perform the obligatory, introductory of any programming lesson: print the string "Hello World!" on screen (I promise I'll keep the trial and errors to an abridged version).

  1. Type-in Get-Command at the prompt
  2. Observe the output and see if any of the command contains descriptions that indicates it is a command for printing anything on-screen by using guess-words such as: "Print", "echo", "Write", "Response", or any other words from whatever your other experience may have been.
  3. If nothing on-screen indicates as such, then you'll want to type in help [Cmdlet name] at the prompt to read the details one-by-one. Hey at least that's how I started learning PowerShell, by reading documentation as well as by trial and errors.

But, let's use my experience, shall we? Let's just type in the following simple command, and we'll simply get the result we want just as we'd see in Listing 1.

Listing 1: PS C:\Users\antonius> gcm | where {$_.definition -match ".*print*"} CommandType Name Definition ----------- ---- ---------- Cmdlet Out-Printer Out-Printer [[-Name] <string>] [-InputObject <psobje... ps c:\Users\antonius> gcm | where {$_.definition -match ".*echo*"} CommandType Name Definition ----------- ---- ---------- Cmdlet Set-AuthenticodeSignature Set-AuthenticodeSignature [-FilePath] <string []> [-C... PS C:\Users\antonius> gcm | where {$_.definition -match ".*write*"} CommandType Name Definition ----------- ---- ---------- Cmdlet Write-Debug Write-Debug [-Message] <string> [-Verbose] [-Debug] ... Cmdlet Write-Error Write-Error [-Message] <string> [-Category <errorcat... cmdlet write-host write-host [[-Object] ><object>] [-NoNewline] [-Separ... Cmdlet Write-Output Write-Output [-InputObject] <psobject []> [-Verbose] ... Cmdlet Write-Progress Write-Progress [-Activity] <string> [-Status] <strin... cmdlet write-verbose write-verbose [-Message] ><string> [-Verbose] [-Debug... Cmdlet Write-Warning Write-Warning [-Message] <string> [-Verbose] [-Debug...

From these output we can sort of guess which command we can use, but if in case we're still in doubt we could always do help write-debug, help write-error, etc. Soon after we go through this we'll find the command we want to use is Write-Output.

That's a rather "long" command to type, though. Let's try to see if there's a shorter version of it. For this purpose, let's try what's on Listing 2.

Listing 2: PS C:\Users\antonius> gal | where {$_.definition -match "Write-Output"} CommandType Name Definition ----------- ---- ---------- Alias write Write-Output Alias echo Write-Output

Now that we found what we want, we can try either command aliases just as in Listing 3

Listing 3 PS C:\Users\antonius> write "Hello World!" Hello World! PS C:\Users\antonius> echo "Hello World!" Hello World!

Sure enough, we found both yield the same result

We might wonder, "Why are there two aliases for the same command?" I don't really know the answer to that question other than perhaps the alias write is the built-in alias for Write-Output and perhaps the alias echo is simply a way to help those who are used to writing .BAT scripts to transition a little more easily to Windows PowerShell. Whatever the answer to that question is rather irrelevant; what's more important is that now we've gone through the basic exercises in learning each PowerShell command.

Wait wait wait!!! We're not done here!

What's all that business with the where command and the rest of the strings following it?

No, I didn't cheat :)

I simply wanted to shortcut all the trial and errors I went through in learning PowerShell without filling the content of this notes full of garbage. Trial and errors, after all, are things we each can do individually on our own time. As for the shortcut strung with the where command, I'll note an explanation of it another time.

Tuesday, March 03, 2009

Basic Windows PowerShell Commands

Windows PowerShell is relatively new shell command interpreter in comparison to the venerable CMD, CScript, and Windows Script Host.

Just like any shell script, it isn't really difficult to learn simply by trial and errors as long as we get the few basic commands down so we can drill further to other commands we seek to use.

The most basic command we should know is, of course, help.

Get-Help

As the command name suggests, it is the single command we use to see the details of a particular command we submit as a parameter to the help command. Listing 1 below illustrates the help command execution.

Listing 1: PS C:\Users\antonius> help help NAME Get-Help SYNOPSIS Displays information about Windows PowerShell cmdlets and concepts. SYNTAX Get-Help [[-name] <string>] [-component <string []>] [-functionality <string []>] [-role <string []>] [-category <string []>] [-full] [<commonparameters>] Get-Help [[-name] <string>] [-component <string []>] [-functionality <string []] [-role ><string []>] [-category <string []>] [-detailed] [<commonparameters>] Get-Help [[-name] <string>] [-component <string []>] [-functionality <string []>] [-role <string []>] [-category <string []>] [-examples] [<commonparameters>] Get-Help [[-name] <string>] [-component <string []>] [-functionality <string []>] [-role <string []>] [-category <string []>] [-parameter <string>] [<commonparameters>] DETAILED DESCRIPTION The Get-Help cmdlet displays information about Windows PowerShell cmdlets and concepts. You can also use "Help {<cmdlet nam e> | <topic-name>" or "<cmdlet-name> /?". "Help" displays the help topics one page at a time. The "/?" displays help for cm dlets on a single page. RELATED LINKS Get-Command Get-PSDrive Get-Member REMARKS For more information, type: "get-help Get-Help -detailed". For technical information, type: "get-help Get-Help -full".

It's so helpful that we can simply type help help at the prompt to display the details of the help command itself. As we examine the command output's "Related links" section, we see three other commands related to the help command. All the three new commands we found here: Get-Command, Get-PSDrive, and Get-Member are part of the important basic commands we will discuss more thoroughly a little later.

Get-Aliases

"Shallow Hal wants a gal."

The second basic command that is most useful to expedite our PowerShell command study is Get-Aliases also aliased as gal. First, we're gonna combine gal with the first command we learned earlier: help in Listing 2. Then, we'll try to see if sending the command twice to the shell prompt, one as the command call itself and another as the paramater to the command call gal gal in Listing 3.

Listing 2: PS C:\Users\antonius> help gal NAME Get-Alias SYNOPSIS Gets the aliases for the current session. SYNTAX Get-Alias [[-name] <string []>] [-scope <string>] [-exclude <string []>] [<commonparameters>] DETAILED DESCRIPTION The Get-Alias cmdlet gets the alternate names for cmdlets, functions, and executable files that have been established for the current session. This collection includes built-in aliases, aliases that you have set or imported, and aliases that you have added to your Windows PowerShell profile. If you specify one or more aliases, Get-Alias gets the alias object and displays its properties, including the object that was aliases, such as the full name of a cmdlet. This feature is made available by the Windows PowerShell Alias provider. RELATED LINKS Set-Alias New-Alias Export-Alias Import-Alias REMARKS For more information, type: "get-help Get-Alias -detailed". For technical information, type: "get-help Get-Alias -full".Listing 3: PS C:\Users\antonius> gal gal CommandType Name Definition ----------- ---- ---------- Alias gal Get-Alias

See! It's simple right? From Listing 2, we find the usage details of the command gal, and from Listing 3, we find that gal itself is an alias of the command Get-Aliases.

But, but, but... How did I know in the beginning that help and gal are commands we can execute? The answer is as ordinary as it could be—I guessed the first command: help presuming that a program usually has a variation of help, --help, --h, man or the old-school /? in some sort of form even without reading its documentation. As for the command: gal, after having found out that while the command help could be executed and yields an output indicating the actual command name: Get-Help, I simply sought in MSDN PowerShell site a reference entry pertaining to available command aliases.

Up next... We won't need to go through the details of each command, but will start our PowerShell exercises by using the three new "related" commands we learned earlier from Listing 1.

Tuesday, February 24, 2009

One ID to rule them all!

Having an OpenID is a cool thing. In theory, I wouldn't have needed to register for any other account ever. Alas, most ideals are just that: ideals. No, I'm not saying anything bad against OpenID; I'm only saying that even with the best intention we still frequently are unable to realize the full potential of the idea's ideals.

Take SourceForge.Net for example, it's one of sites I frequented. Sure it does take my OpenID to authenticate me when I logged into the site, but it still requires me to bind to a local SourceForge account if I want to use it to access certain things such as its CVS repositories. C'est la vie.

The OpenID provider I chose for my use is MyOpenID.com. I like MyOpenID.com because it is one of only a few (as of this writing) strong authentication providers who uses SSL certificates and Windows CardSpace/InfoCards which enables auto-authentication. This is so that while I do have a password for my OpenID account, I won't need to really memorize it or use it to sign into any sites using my OpenID account.

To demonstrate:

  1. Go to MyOpenID.com
  2. Sign in (if you already have an OpenID account)
    Type in your OpenID account
  3. Choose a sign-in method
    Sign in using SSL P12 certificate
    Or
    Sign in using InfoCard
  4. You'll be presented with a certificate you've previously created and install in your browser
    SSL P12 certificate
    Or be prompted to send your Microsoft Windows InfoCard you've previously linked to your OpenID
    Microsoft Windows CardSpace - InfoCard
  5. Click sign-in
    OpenID sign in
  6. And swweeet!! I'm in... quick & easy.

Friday, April 25, 2008

Information is to knowledge as...

Bit is to Byte.

Byte is to data.

Data is to information.

 

A computer is such a nice tool to collect, prepare / process, and consume knowledge. But nice is different from easy. The level of ease in using computer for the aforementioned activities however are usually inversely proportional to one another. For example, if it could be considered easy to collect data, it can be reasonably said (and observed) that the data processing is relatively more difficult than the its collection; or so the logic dictates, for what it's worth.

Fast forward to preparing cubes for SQL Server Analysis Services, I found myself trying to figure out how to prepare an ease of processing for my work product's audience, starting with its setup. After a little bit of struggle through the various binaries in my machine, I found the following steps helpful for those of you trying to do the same:

Local environment variable path setup:

  1. Add to your local environment path an entry pointing your VS.2005 IDE location (screen Evp1.1 - 1.4).
  2. Add to the same local environment path another entry pointing to the location where you find Microsoft.AnalysisServices.Deployment.exe, if it isn't already there. (Notes local environment path entries are separated by semi-colon).

Screens:

Evp1.1evp11 Evp1.2evp12

Evp1.3 evp13 Evp1.4 evp14

 

The lazy version:

  1. prompt:> devenv [solution filepath and filename] /deploy

Well... sure you might run into a couple of pop-up dialogs, but just a couple of OK clicks without knowing what they mean will put you back on the processing track. No worries though, even when you don't click the buttons until the end the show will go on until completion with the exception that the thread is still be hanging until said clicks are made.

If you're bothered by the only seemingly semi-autonomous run (since you still may be needed for those two manual clicks), here's another way to do it... properly... starting with the same local environment path setup steps above, then followed by these steps:

  1. Build the .asdatabase file from your solution file using prompt:> devenv [solution filepath and filename] /build
  2. The deploy using prompt:> microsoft.analysisservices.deployment [solution filepath]/bin/[project name].asdatabase /s:[deployment log filepath and filename]

A word of caution: Don't be alarmed if your screen seemingly freezes during the deployment; this will likely be the scenario depending on your hardware configuration and the volume of data in your database that Analysis Service engine processes.

Why do we want to go through this when we can just load the solution file in VS.IDE then with just a few clicks to the above easily without having to memorize seemingly arcane and puzzling commands and steps? There are several different answers to this, but my favorite one doesn't have anything to do with it as knowledge that reliable technician needs to have; rather, it has to do with the pursuit of knowledge itself.

If our knowledge is the sum of our experience, and if we postulate that human beings learn more from difficult experience than an easy one, then it follows that by doing the above steps we will retain this knowledge longer that had we just done the usual mouse-clicks. And that my friend is what knowledge is to an application...

Friday, February 01, 2008

Holy chocolate fudge!!! Quick! Show the window pronto!

The first month of 2008 came and went.

We've gone through 31 days of a new year so quickly, we barely had a chance to reflect on the past year due to piles of backlog tasks that seems to increase faster than we can keep up. It's a blessing and a curse.

Speaking of a curse, I was in the middle of debugging an application last night and was unable to find the Immediate Window in my VS2005 IDE. It had been there before; I sought for it in all of the menu and sub-menu items and couldn't find it. I still don't know what caused its disappearance. Perhaps it was a recent VS2008 IDE installation that might've affected the 2005 environment settings; perhaps others unknown reasons.

Suddenly, a simple thought sprang to mind bulb : go to Tools/Customize/Debug and simply add it back-in to the menu bar and my shortcut toolbar. Et voilà! My indispensable Immediate Window returns; and all is well.

Friday, January 04, 2008

2008

A few days into the new year, a sleeping sick baby and an offline HQ—I found a few moments of peace.

So here's a piece of advice: When trouble brews, be calm and proceed to the nearest exit, brew a cup of hot cocoa, lounge, and read.

If your trouble is specifically of the message:

"The current identity (NT AUTHORITY NETWORK SERVICE) does not have write access to 'C:\WINDOWS\Microsoft.NET\Framework\V2.0.50727\Temporary ASP.NET Files'. This error may be cause by having installed visual studio C# or by group policy settings."

Please, oh please don't manually assign the permission to the folder through the folder property; you should instead run the following from a command prompt to wish your trouble away:

prompt:>c:
prompt:>cd \windows\micro*\frame*\v2.0*\
prompt:>aspnet_regiis -i -enable

Happy New Year!