Category Archives: Scripting

Change Active Directory DisplayName Script

I recently imported users to Active Directory and made a mistake on the import script. I accidentally swapped the first name and last name within the Name and DisplayName fields for a few hundred users. I didn’t really want to fix this manually- so I did some digging and pieced together a couple of scripts to do just what I needed within powershell.

This is what I had:

Name: Hunter Daren
DisplayName: Hunter Daren
GivenName: Daren
Surname: Hunter

Basically – I had the correct Given and Surname – but mixed them up in the script for DisplayName and Name.

  1. Open windows powershell with administrator privileges.
  2. You will need to import Active Directory Module. import-module activedirectory before you can run the commands below.
  3. To swap the DisplayName – I created the following script:
    Get-ADUser -SearchBase ‘OU=Your,OU=Organizational,DC=test,DC=com’ -Filter * -Properties displayname | % {Set-ADUser -Identity $_ -DisplayName (“{0} {1}” -f $_.GivenName,$_.Surname)}You will just need to swap out your SearchBase with the OU information where your users are located.
  4. Here is the script I used to change the Name in Active Directory:Get-ADUser -SearchBase 'OU=Your,OU=Organizational,DC=test,DC=com' -Filter * -Properties displayname | % {Rename-ADObject -Identity $_ -NewName ("{0} {1}" -f $_.GivenName,$_.Surname)}

These two Active Directory Scripts will change the Name and DisplayName for all users in the specified OU. Keep in mind – I was changing to first name and last name.

You can change the ("{0} {1}" -f $_.GivenName,$_.Surname) to meet your specific needs. ("{0} {1}" -f $_.GivenName,$_.Surname) is just concatenating the First Name and Last Name together with a space between.

For example – you might want to use ("{0}.{1}@{2}" -f $_.GivenName,$_.Surname,"yourdomain.com") which would give you firstname.lastname@yourdomain.com

How to allow non-admin mac user to use App Store

How to allow non-admin mac user to use App Store

There are times you may need to provide a non-admin user access to purchase and install apps from the Mac App Store.  However, out of the box – the Mac Operating System does not allow this due to that user not having full permission.  When a user installs an app – it installs to the /Applications folder which requires administrative rights. In a situation where giving admin rights to that user isn’t feasible – there is a work around.

I have a non-admin user named “Tom Foolery”. I would like him to stay a standard user – but have access to purchase and install from the App Store.  Here is what I do:

Add Non-Admin User to _appstore Group

  1. Log in to the computer as a user with Administrative Rights
  2. Open up your command line by clicking the Spotlight   located in the top right of your Mac screen to search for the Terminal command line.
  3. Type in “Terminal” and then click on the Terminal app. 
    Once Terminal.app opens  you are now ready to type commands to add the non-admin user to the _appstore group.
  4. Type the following command:
    sudo dscl . -append /Groups/_appstore GroupMembership tomfoolery

    You will need to replace “tomfoolery” with your username. Don’t know what username you should use. Use the following command to list the users on your OS.

    sudo dscl . -list /Users

    Be sure to copy the username exactly as listed and insert it into the dscl command.

  5. Now login as the non-admin user and enjoy your access to the App Store!

Keep In Mind

When a user installs an app from the App Store – the App Store is actually controlling the installation and setting the permissions.  Meaning – an app installed by a non-admin user is going to be installed in the /Applications folder as user System and group Wheel.  What this means is that they will not be able to delete the app after they install it because they won’t have permission.

BASH Scripting – How To Create Executable Script

There are many ways to achieve this – but I find this to be the fastest way as it is all done through command line.

Creating The Script File

Open Terminal.app from /Applications/Utilities/Terminal.app

In the Terminal window that opens, we are going to create a directory called scripts on our desktop and then create a shell script file within that directory – use the following command:

//"mkdir" creates a directory on your desktop - no different than right clicking on desktop
mkdir /Users/yourusername/Desktop/scripts

//"touch" just creates an empty file with a name and extension you specify
touch /Users/yourusername/Desktop/scripts/kickstartscript.sh

We also need to make the script executable.

//chmod is used to set permissions - in this case, executable permissions
chmod +x /Users/yourusername/Desktop/scripts/kickstartscript.sh

You now have an executable file. You can use any text editor (may I suggest TextWranger – just do a google search for it) to open the file made in the scripts directory on your desktop. You may also use VIM or other command line text editor as well, but chances are if you are reading this – you would be better suited to start with a program based text editor like TextWrangler.

Once you have the file open – all you have to do is add

 #!/bin/bash 

to the top of your file and you are ready to start scripting.

The line above just tells Terminal that it is a bash file with bash commands.

Thanks for reading!