Archive for January, 2008

As seen on TV

PowerShell is not featured on TV that often. (I wonder: why? Not enough reality show appeal?) Luckily there’s dnrTVthe online TV channel from the creators of one of the most popular mp3 shows .NET Rocks!

Kirk the Poshoholic has just made an appearance on the show, talking about PowerShell and PowerGUI. It is quite fascinating to compare where PowerGUI got from it’s first appearance on Channel 9 awhile ago.

Kirk is going through a lot of the topics:

  • PowerShell basics,
  • Tips for learning PowerShell,
  • How PowerGUI works and can get extended,
  • How to put UI on top of PowerShell,
  • How to debug PowerShell scripts,
  • And much more…

By the way, when you are done with the Kirk’s episode check out the previous shows archive. They have already had another show on PowerShell with Scott Hanselman, as well as a lot of great other shows on .NET, ASP.NET, AJAX, Workflow Foundation, LINQ, Ruby and much more.

Go check out Kirk’s demo on dnrTV!

Tags: , , ,

Dude, where’s my PowerShell profile?

PowerShell profiles is the “stuff” that gets loaded each time you use PowerShell. They can load your favorite Exchange management scripts, define the aliases you need, or just give you a nice welcome message.

How do you create a profile? How do you find which ones have already been created on your computer and are already affecting the execution?

The easy way is just using the File / Open Current User Profile or File / Open All Users Profile menu in PowerGUI – see the screenshot below.

Use PowerGUI to Find, View, Edit or Create PowerShell profile

These menu items allows you to see/edit the profiles already present on your computer, and create a profile if it is not there yet.

profile.ps1 profiles are guaranteed to work across all PowerShell applications on the machine. Microsoft.PowerShell_profile.ps1 might not work outside the powershell.exe “blue” console (for example, ISE will not use it – but PowerGUI by default will).

You can read more about PowerShell profiles in MSDN.

Tags: , ,

Scotty, get well soon!

Not the kind of news I enjoy blogging about. Alex Binotto has just told me that Scotty McLeod is in the hospital. Last night while going home he was hit by a train and is now in critical conditions fighting for his life. 😦

Scotty was one of the guys evangelizing PowerShell in its early Monad days. He helped Richard found the first PowerShell Usergroup. Later he became the leader of the UK Windows Server usergroup.

Scotty is absolutely amazing: funny, geeky, and extremely knowledgeable and insightful.

We all hope that Scotty gets well soon!

[Update] Thanks to Keith and Adam here’s some updated info:

He’s in the Neurology Intensive Care ward of St Georges Hospital.

  • His condition has improved since yesterday
  • He’s on a ventilator to breath.
  • Hes not conscious.
  • He’s stable.

Not much to go on, but I was told he’s allowed to have visitors.

[Update 2: Jan 25] Thanks to Gordon:

The situation seems less dire than at first. He cannot be fully assessed until they start to wake him up, which will not be until after his jaw is fixed. The doctors are planning to take Scotty to surgery to fix the broken jaw – a good sign indeed.

Scotty’s family is with him. Obviously it is not the right time to call or visit him, but sending a card to demonstrate support to Scotty and his family might indeed be a good idea.

[Update 3: Jan 28] From Richard:

The jaw reconstruction went well and they have taken him off sedation but he hasn’t woken up yet. They will be doing a CT scan soon.

It looks like Scotty could either regain consciousness very soon or its going to be a long haul.

[Update 4: Jan 29] Richard quoting someone who visited Scotty:

His condition is currently described as stable but he is no longer on sedatives and has not woken up yet. The doctors say that it’s a waiting game now for the next couple of weeks to see if he comes out of the coma.

There is nothing medically stopping him from reviving at the moment but they are going to carry out some further tests to rule some things out.

[Update 5: Jan 31] From Mark:

I went to see Scotty this afternoon. It was the first time I’d seen him since the accident but his family tell me that there’s been a big improvement – the swelling and bruising is starting to go down, he’s off the ventilator and may even be moved from Intensive Care to a High Dependency Unit once a bed is available.

The big news was that whilst I was there he opened one eye and appeared to be watching me – probably thinking bugger off and stop blathering nonsense!

There’s a long way to go yet though – he’s still unconscious (I’m told he can hear visitors though and I’m pretty sure he was watching me) but his family certainly appreciate the visits from friends, colleagues and associates.

[Update 6: Feb 02] Please the comment Jan recently left on this blog. Also, here’s what Richard is forwarding from Scotty’s brother:

He has been moved from the Neurological ICU to the High Dependency Ward. Its called Brady or Brodie Ward. Its in the same building on the same floor as the ICU just at other end of corridor.

He is still unconscious but is now off the ventilator. He is showing more and more eye movement and more coordinated movement, especially of his arms. This is taken to be good signs and they are looking for the progress to continue.

Visiting times are 11-1 and 3-8. Visitors are more than welcome.

[Update 7: Feb 08] See the comment by Scotty’s brother below. There’s apparently great progress with Scotty now opening his eyes and moving his limbs. Visits are greatly encouraged and appreciated. See the comment for more details.

[Update 8: Feb 12] Update from Steve Lamb:.

I saw Scotty sat in a chair (beside his bed) with his eyes open and apparently awake with an old friend of his (a former lodger) talking to him. He commented that he could see improvements in Scotty’s awareness over the previous day and a half.

Scotty seemed to be aware of some of the things going on around him though his interactions were limited to hand squeezing and periodically pointing to his right ear – I learned that this is a request to have his ear rubbed which seemed to give him comfort.

He seemed to squeeze my hand more as I told him of our plans for the Windows Server launch, particularly about James’ Powershell session.

Scotty was also exploring his Mum’s watch and rings plus the intravenous trip with his fingers.

It’s great that Scotty is becoming more and more aware of the World around him.

Scotty’s Mum, Dad and brother (Murdo) expressed their wish for as many of Scotty’s friends as possible to visit him and talk about anything he might relate to. The family each expressed their amazement at the number of people who know their Son and the online support you have given.

See comments to this post for contact information and please pay Scotty a visit if you are in the area.

[Update 9: Feb 22]: Scotty is being moved to Sycamore Ward, on Level 4 of the Kingston Surgical Centre, visiting times 15:00-20:00.  The nearest railway station is Norbiton and this is literally across the road and down the hill from the hospital.  If you need maps the hospital website is http://www.kingstonhospital.nhs.uk

He is getting better and better every day. Interacting with people, smiling, moving, and so on. Please subscribe to the comments feed for this post to get the updates posted there.

As mentioned multiple times here: visits are highly encouraged (make sure you use his full name – Malcolm McLeod – when inquiring at the reception) and very important for Scotty’s recovery.

[Update: Feb 2009] Actually, this whole post and all the comments below are now a little bit of history – or a fairy tale with a very happy ending. Scotty recovered and is even blogging now at http://scotty-mcleod.spaces.live.com, he and Jan got married and are living together happy ever after. I wish all stories in this world went like that. 🙂

PowerGUI 1.0.13 ships

PowerGUI has just got updated and there are a lot of great new features.

The PowerGUI main IT Pro UI has multiple improvements ranging from improved code generation and preserving window sizes, to the brand new WMI Browser pack right within the console!

The script editing got a lot of improvements: F1 help, ability to supply command-line parameters, background syntax check, intellisense for WMI classes, and much more.

Richard has already blogged about some of the features he liked the best.

So whether you are using PowerShell to manage your AD, Exchange or another platform, or you are a hardcore scripter – go get the latest version of PowerGUI. The price is still the same – $0.00. 😉

Tags: , ,

AD User Provisioning from CSV Got Easier

Creating new AD user accounts from a csv-file data has become even easier. In versions prior to 1.0.6 you could import a csv file, and then use ForEach-Object and manual column mapping to assign the values to the attributes (for example, see this post on populating test environments):

Import-CSV c:\users.csv | ForEach-Object { New-QADUser -Name $_.Name -SamAccountName $_.Name -Department $_.Department -ParentContainer mydoman.local/demo }

This works but is somewhat redundant. If the CSV file already has a column named Name, why wouldn’t PowerShell assign that column to the Name property automatically?

This is exactly what we have added in AD cmdlets 1.0.6. Now you no longer have to use ForEach-Object (pipe import- directly into new-!) and don’t need to specify the parameters which are already in the CSV file!

This means that if I have a csv file like this:

Name,samAccountName,Title
"Aaron Nelson",anelson,Engineer
"Justin Starin",jstarin,Janitor

I can create these two new user accounts with the simple command below:

Import-Csv users.csv | New-QADUser -ParentContainer mydomain.local/test Import

Notice how much simpler it has become compared to the one used in the beginning of the post!

But wait, it becomes even better! You can mix and match the approaches by using some of the parameters from the CSV and adding others in the command-line. Let’s use the same CSV but set the City property to the accounts we create:

Import-Csv users.csv | New-QADUser -ParentContainer mydomain.local/test -City Melbourne Import

This takes the Name, SamAccountName, and Title from CSV, and adds the City from our command:

Get-QADUser -SearchRoot mydomain.local/test | Format-Table Name,samAccountName,Title,City

Name          samaccountname Title    City
----          -------------- -----    ----
Aaron Nelson  anelson        Engineer Melbourne
Justin Starin jstarin        Janitor  Melbourne

The whole purpose of PowerShell and AD cmdlets is to make AD management easier and more intuitive, and it is good to see another step in that direction.

By the way, this feature was influenced by the requests we were getting from the community: for example, from Jonathan Walz and his comments here. Thanks Jonathan and everyone on the AD PowerShell discussion forum!

Tags: , , , , , , ,

Measure vs Count vs $i++

Suppose you need to count the number of certain objects (e.g. users in your domain) and you know that the number (and object size) is big, what’s the best way of doing that?

The first one that pops to mind is: just get the collection and check the Count property:

(Get-QADUser -SizeLimit 0).Count

The problem with that is that you are getting (and keeping) all the objects until the enumeration is over, and only check the count after that. This means that in large environments you can easily run out of memory. In my domain (which is not huge at all), this command uses 153 MB of memory. And if I go for a bigger collection by retrieving all AD objects (running Get-QADObject) I run out of memory before the command finishes.

So, let’s look for alternatives. Why don’t we just pipe the output to the Measure-Object cmdlet which by default simply counts the number:

Get-QADUser -SizeLimit 0 | Measure-Object

The cmdlet will be getting the objects through the pipeline and thus will not need to keep them all, so it should use less memory, right?

Wrong. It looks like due to lack of optimization Measure-Object is actually keeping the whole collection of real objects instead of just counting them and letting them go. Thus, it produces the exact same hit on your system and uses awful amounts of memory (hope that this gets fixed in v2! anyone from the PowerShell team reading this?)

So the right way of counting objects is actually to do that yourself by simply incrementing a counter variable:

Get-QADUser -SizeLimit 0 | ForEach-Object {$count++}
$count

On my system this used only 27 MB instead of 153 MB used by Count and Measure-Object – a 6 time reduction!

And, the ratio is going to be even bigger if the number of object being counted grows.

Summary: standard solutions ain’t necessarily the best ones. In this particular case, manual $count++ works more optimally than standard Measure-Object. PowerShell provides multiple ways to solve the same tasks and the performance/resource-intensiveness differences between them can be huge.

For other optimization tips see also: Optimizing PowerShell Performance and Memory Consumption

Tags: , , , , , , ,

KB: Domain either does not exist or could not be contacted

ISSUE

AD cmdlets are issuing the following error message: “The specified domain either does not exist or could not be contacted“.

The message is displayed even though native tools, such as Active Directory Users and Computers, can connect to the domain with no issues.

Explicitly specifying credentials or domain/DC name (in a cmdlet or Connect-QADService) does not help and leads to the same error message.

CAUSE

AD cmdlets version 1.0.6 have a software issue which leads to this error message in the following circumstances:

  • Netbios domain name and Name attribute of the domainDNS object do not match.
  • Global Catalog is not available.

VERSIONS AFFECTED

AD cmdlets version 1.0.6.

RESOLUTION

Upgrade to a later version or install a patch from http://www.powergui.org/thread.jspa?messageID=15755.

ACKNOWLEDGEMENTS

Thanks to everyone who reported the issue at the AD PowerShell discussion forums and helped troubleshoot and narrow down the issue.

Tags: , , , , , ,

Copy AD accounts with PowerShell

Being able to copy AD accounts with one line of PowerShell code is probably my favorite feature of AD cmdlets RTM version.

Suppose you have an account the properties of which you would like to use to create another account? You probably want the new account to have a different name, password, etc. but it needs to have the same location, department and other attributes. The solution is extremely easy and straight-forward. You just need to do Get-QADUser for the sample account, and pipe into New-QADUser while specifying the new location and unique properties.

For example:

Get-QADUser 'James Johns' -export | New-QADUser -ParentContainer mydomain.local/test -Name 'Janny Grant' -SamAccountName jgrant -DisplayName 'Janny Grant' -FirstName Janny -LastName Grant -UserPassword 'J@nnysPwd' -import

One gotcha is that it will not copy the group membership, so you will have to use another oneliner for that:

(Get-QADUser 'James Johns').MemberOf | Add-QADGroupMember -Member ps64\jgrant

How cool is that? 😉

Tags: , , , , , ,

Specops Command/PowerGUI Press Release

Last month I blogged about how you can use PowerGUI and Specops Command to not only create and debug your PowerShell scripts but also to deploy them across multiple desktops in your network. Today the press release about the integration went live.

Here are the quotes from the press release:

The integration makes it possible to use the powerful and free PowerShell script editor, Quest PowerGUI, directly from Specops Command and thus provide features like IntelliSense (to access descriptions of functions) and debugging capabilities when editing PowerShell scripts.

“The incredible synergy created by integrating Specops Command and Quest PowerGUI into a single powerful solution is very exciting,” said Dmitry Sotnikov, New Product Research Manager at Quest Software. “Giving users the ability to invoke PowerGUI Script Editor to edit and debug their scripts and then use Specops Command to distribute the script to computers in the network makes perfect sense.”

“The combined power and ease of use of Specops Command and Quest PowerGUI will forever change the landscape of distributed Windows-based computer management and will make Windows PowerShell the number one solution used everywhere — not only for administering a small number of servers, but tens of thousands of computers at a time,” said Thorbjörn Sjövold, CTO of Special Operations Software. “Also, by simply using the free Quest PowerGUI with the free version of Specops Command, Logon and Startup scripts as we know them today will never be the same.”

See full text here.

Tags: , , ,

Kirk the Poshoholic becomes MVP

Kirk “Poshoholic” Munro has just got his MVP award! This is a great news (especially for the PowerGUI team 😉) and a well deserved award considering Kirk’s everyday participation in all PowerShell newsgroups and forums out there, his PowerShell talks in Canadian usergroups, and his willingness to use every opportunity to promote this technology. (Hey, frankly, they should have given him the award just for becoming the first self-acknowledged Poshoholic out there! ;))

Congratulations!

Who else got the award yesterday?


My Recent Tweets

Legal

The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

January 2008
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  

%d bloggers like this: