Automation is a key element in the success of day-to-day routines of a systems administrator. Be it using special tools to query a few thousand computers in the domain, checking the health of hundreds of servers, or even crafting your own script to check the status of OS updates on your computing endpoints, automation ensures that a sysadmin is able to generate these types of report in a timely, efficient and accurate manner. I have been involved in so many tasks wherein I had to dig deep in my scripting cheatsheet to come up with scripts to check and manage the six-thousand-over computers that I administer. Fact is, I also contribute my fair share of scripts in the Technet's
IT Pro Code Gallery in my own little way.
One such script delves on changing the "profilePath" property of thousands of users (
this one is from the Technet forum). Being the KISS (that is "Keep It Simple and Straightforward" for you) advocate that is me, I went to create a simple, short, quick and dirty script.

First, I had to generate a list of all the users in my domain. I can, in fact, accomplish this using adsi within the main script itself. However, the fastest way to do it is actually running the
net users /domain command from the CLI and piping the output to
users.ini.

The main body of the script shown is as simple as it can get. The domain is defined (strDomain), so is the source file containing the list of all the users in the domain (users.ini). The script reads each line of the users.ini file and passes this to the ChangeUserProfilePath sub-routine (together with strDomain).

The ChangeUserProfilePath sub-routine has the old and the new profile paths defined (oldProfile and newProfile). The Replace string function is used to substitute oldProfile with newProfile. The resulting string, strNewProfilePath, is then set to the "profilePath" property of the user account being processed. An initial check is made to verify if the oldProfile string is located in the user's profile property (sUser.Profile). If and only if this condition is met is the profilePath updated.
No comments:
Post a Comment