Archive | PowerShell RSS feed for this section

QuickHitter 02 : Indexing Powershell Scripts

It was until I recently had a pc failure that I remembered what it felt like not to be able to have windows search inside powershell files. By default, the indexing options are set to only index the “File Properties” but not the “File Contents”. There may be other cases where this is beneficial to you, but this one was the biggest for me. For me, it was a simple fix:

Start -> type index in white box, select Indexing Options.
Select Advanced, File Types tab.
Find ps1 and change it to “Index Properties and File Contents”, click OK and move along.

Caution: You will see the notice that you are about to be grab a cup (few pots on my system) while the index rebuilds so do this when you have some time.

You could also follow the instructions on the bottom of this technet wiki for a more granular approach.

Have you found any other files that would benefit from this? It’s been so long since I explored this and I’d love to hear other thoughts.

Comments { 1 } Posted on January 30, 2013 in PowerShell, SQLServerPedia Syndication

Move Computer to New OU Using PowerShell

I’m going to assume you have some tool you are using for PowerShell if you are reading this. PowerGUI is the one that I like the best currently. Once you’ve installed that, you research and download the Quest AD cmdlets. You should be set up at this point.

I had run into this issue in the past, albeit learning the hard way when I move “just a few” computers into the wrong OU. So this time I thought I would ask more questions and do more testing before I pulled the trigger. You can find where the journey begin by looking at this Forum Thread over at

To summarize, I wanted to get a list of computers and pipe it into PowerShell to move the computers to a new OU if the name matched exactly. The code that I had used before would move both Computer1 and Computer12. So I decided to ask the experts in the field and through a little trial and error I found a working solution. Here’s how it ended up working.

csv file looks like this:
computer1, Computers/Big Building/Windows XP SP2 Test Group

PowerShell looks like this:

#take the -WhatIf off when you are ready to actually do it
$csv = Import-Csv C:\ps\PSTextFiles\yourFile.csv
foreach($computer in $csv){
# Display QADComputer for each item in the CSV object
Get-QADComputer -Identity $computer.object | Where-Object {$computer.object -eq $} | Move-QADObject -To $ -WhatIf

Dmitry Sotnikov (Blog|Twitter) goes even further to blog about how we should be explicit in what we are asking for.

Poshoholic (Blog|Twitter) mentions the post in his PowerGuide – PowerGUI Weekly News.

Comments { 0 } Posted on April 19, 2011 in Active Directory, Networking, PowerShell

Get Going on Powershell

By now, I hope you have heard of a wonderful tool called Powershell which can make your life easier in some respects. Whether you are needing to interact with SQL Server, Exchange, or Active Directory there are resources available to guide you along the way. I’m not going to try and reinvent the wheel when it comes to great blog posts, so there may be a good deal of linking and summarizing.

Powershell is a command-line shell that will allow you to perform administrative tasks that would have been much more tedious if attempted in a different manner. It’s built upon the .NET so it can interact with .Net Framework objects.  Microsoft came out with Version 2.0 and released it with Windows 7 and Windows 2008 R2 (although you have to enable it).

If you already have PowerShell 1.0 installed then you may want to remove it first, unless you want to look into running both versions. You can also see how to check for a PowerShell installation. To correctly uninstall PowerShell 1.0 you can follow the instructions on MSDN.

If you haven’t already got Powershell 2.0, you’ll want to get that by downloading the Windows Management Framework Core. That core package comes with Windows PowerShell 2.0 and Windows Remote Management 2.0 (also known WinRM).

In regards to Powershell, you will now have two ways to test-drive your shiny new toy. It’s probably a good idea to try and hold off using the PowerShell ISE (Integrated Scripting Environment) in favor of using the basic PowerShell interface while you are starting out.

Getting Started
Windows PowerShell on MSDN
Why This SQL Server DBA is Learning Powershell
I’m a SQL Server DBA, and I’m in Love with PowerShell
Mastering PowerShell eBook with Dr. Tobias Weltner
Effective Windows PowerShell: The Free eBook
PowerShell in Practice (not free, but well worth it.)

Little Deeper
Administrator’s Guide to Windows PowerShell Remoting

Third Party PowerShell Editors
Once you begin to get a basic understanding of how things work I’d start looking at your other choices for editors. I use PowerGUI, but there’s also PowerShell Plus and Sapien’s PrimalScript. You can get more info about the comparison between the three from Don Jones and Michael Otey.

Idera Active Directory Scripts pack

SQL Server PowerShell Extensions
What’s New in SQLPSX 2.3

Active Directory cmdlets from Quest

Other Resources[0].Type=ScriptLanguage&f[0].Value=Powershell&f[0].Text=Windows%20PowerShell

Comments { 1 } Posted on November 29, 2010 in Education, PowerShell, SQL General, SQLServerPedia Syndication