Quick Fix: Get-MDTComputer by Description Broken in the MDT PowerShell Module

The short story:

Launch SQL Server Management Studio, expand the MDT database > Views > right-click on dbo.ComputerSettings and click on “Design”, tick the “Description” column in the CI table in the View.

The long story:

During my experiments with using PowerShell to automate Windows imaging and deployment tasks I’ve been working with the MDT database module, provided by Michael Niehaus from Microsoft.

I was disappointed to find the Get-MDTComputer cmdlet is broken somewhat, as in you can’t retrieve a computer record from the database matching a description. This is what the error message says when you try:

image

I thought I’d take a look at the Get-MDTComputer function in the PowerShell module and saw that the function was doing nothing more than building a SQL statement and querying the MDT database. Specifically, it was querying the “ComputerSettings” table as shown below:

image

This, along with the error message we saw earlier mentioning “Invalid column name ‘Description'”, led me to fire up the SQL Server Management Studio to examine the “ComputerSettings” table, only to find there isn’t a table with that name but there was a “View” called “ComputerSettings”.

I right-clicked the “ComputerSettings” View and selected “Design” and immediately saw what the issue was here. It was apparent that the problem was that the “ComputerSettings” View didn’t include the “Description” column from the ComputerIdentity table.

So the solution is to tick the checkbox next to the “Description” column in the CI table in the View:

image

 

And here you can see the Get-MDTComputer cmdlet working with the –Description parameter:

image

Advertisements

Adding Multiple Users to a Group in Active Directory Using PowerShell and CSV

Today I picked up a request from an owner of a shared drive asking for a list of her colleagues to be given access to the drive. This required finding the right group in Active Directory and making each person a member of the group.

With a total of 25 people in the list I knocked up a PowerShell script to make things a little easier for myself. The idea was to import a list of login id’s (samAccountNames) from a CSV file and add them to the required group programmatically.

I started with a simple CSV file in Excel as below:

csv-addmultipleusers

And the script itself is only a few lines of code:

# Import active directory module for running AD cmdlets
Import-module ActiveDirectory

#Store the data from UserList.csv in the $List variable
$List = Import-CSV .\UserList.csv

#Loop through user in the CSV
ForEach ($User in $List)
{

#Add the user to the TestGroup1 group in AD
Add-ADGroupMember -Identity TestGroup1 -Member $User.username
}

Continue reading

Importing Users into Active Directory from a CSV File Using PowerShell

There are two aspects to this post – first is the CSV file with the user data and then there’s the PowerShell script to import the data into Active Directory. As an example, this how-to post will only set the first name, last name, username and password values for our user objects.

Preparing the CSV file

A template of the CSV file with sample data can be downloaded here (save it with a .csv extension). Here’s what it looks like:

CSV template

Populate the CSV file with the user data, making sure you enter the Distinguished Name of the Organisational Unit in the OU field.

Follow these instructions to check the format of an OU’s distinguished name:

  • Launch the Active Directory Users and Computers console
  • Select Advanced Features from the View menu
  • Right click on an OU and select Properties
  • Look for distinguishedName in the Attribute Editor tab

Importing using PowerShell

The PowerShell script is my own work, written by myself. As always, I’ve included comments to explain the code to help understand it better.

Import AD Users Script

Download the PowerShell script and modify it to suit any changes you may have made to the CSV file and save it with a .ps1 extension.

Make sure you have the CSV file and the script in the same directory to begin with. To run the script simply right-click on it and select “Run with PowerShell”. Launch Active Directory Users and Computers console to check if the import was successful.

Follow Me, Myself and IT on Twitter:

Building a GUI for Windows PE

I wasn’t exactly planning to get into this but I got carried away with my research a little and ended up working on this on and off for a while now. I’ve come to realise that this is quite a big project on its own and will potentially keep me away from working with MDT 2010 for some time.

So I’m stalling this project for now and publishing my notes on my research in this post. The point is to preserve my research, notes and the little work that I’ve done so that I can pick up from where I left off if I want to come back to it any time in the future. Also anyone who’s trying to get started with doing something similar to this may find having these notes useful. Continue reading

A little scripting goes a long way

We’re upgrading the Kaspersky network agent at my workplace today, starting off with 50 machines on two clusters as a trial.

This included a few steps as explained below:

  • disabling a running service
  • configuring the service to  start manually
  • changing the power options to stop the machine powering off after 15 mins of inactivity
  • copying a text file to the root of C: drive
  • running setup.exe (a silent install)
  • restarting the machine

This may not seem like a lot of work but I did have 50 machines to repeat this on, and maybe more with the possibility of extending the trial to more machines. So I came up with a quick batch script to do the job for me. Nothing fancy, just a simple little script:

@echo off 
title KAV Update 
cls 
echo. 
echo Disabling PowerMAN service 
net stop PowerMAN 
sc config PowerMAN start= demand 
echo. 
echo Changing power options... done 
powercfg -change "Student Policy - Office" -disk-timeout-ac 0 
echo. 
echo Copying noklmover.txt to the C: drive... 
copy \\server\share\noklmover.txt c:\noklmover.txt 
echo. 
echo Installing new Kaspersky agent setup file... 
pause 
start /wait \\server\share\setup.exe 
echo. 
echo ...Installation complete 
echo. 
echo Task complete on this machine. Restart? 
pause 
shutdown -r -f -t 15

Writing a quick script is a neat way to automate and relieve yourself from a repetitive task a little quicker than doing it manually. I find it very satisfying when I write a script that ‘just works’. The above script is no more than a simple set of instructions but I reckon I have a good aptitude for programming  in general and with a keen interest in scripting I would love to extend to Windows PowerShell one day.

Speaking of which, that ‘one day’ may be coming a lot sooner since I’m about to start studying for the 70-640 exam (Configuring Windows Server 2008 Active Directory). That reminds me, I’ve still got to write a post on my study plans (and more).