Skip to main content

Posts

Showing posts from September, 2015

Changing a Computers Description in Active Directory to Match the currently Logged On User

This is one that I picked up off of PowerShell.com.  The problem is that that the answer is a bit long so I’m posting it here.  The IT Pro in question wants to change the Computers Description in Active Directory to match the login name of the currently logged in user.  A few issues come to mind. 1 – Does all of the clients have RSAT installed?  I’m going to assume no.  That means that we cannot use the Active Directory Modules cmdlets. 2 - Does all of the users have the rights to modify the description field of a client in Active Directory.  By default, they do not.  We will set this up at the attribute specific level. 3 – How will this script run?  We will implement it as a login script. Modifying User Rights First off, let’s tackle the user rights issue.  All users in your domain are able to read the contents of Active Directory.  Only a hand full should be allowed to modify it.  We are going to modify AD to allow for our users to modify just the client Description attribute. 

When to use Single and Double quotes with PowerShell

Here is another one of those enduring questions from my PowerShell classes. When to use single and double quotes. First off we need to establish the object type that is created by both single and double quotes. Take a look at the code below. Both single and double quotes produce a System.String object type. At this point there is no difference between the two. PS C:\> $Single = ''   PS C:\> $Double = ""   PS C:\> $Single.GetType()   IsPublic IsSerial Name                                      BaseType                                           -------- -------- ----                                      --------                                           True      True      String                                    System.Object                                            PS C:\> $Double.GetType()   IsPublic IsSerial Name                                      BaseType                                           -------- -------- ----              

When to use [] or {} or ()

Yesterday I posted a question that comes up often in my PowerShell classes on when to use special variables. Today I am going to post another one. When to open and close code and what characters to use. Indexes of Arrays [ ] The Square braces are used when we want to access an element of an array, also known as a collection. # Accessing Array Elements   # Create an array. $Fruit = "Apple" , "Grape" , "Orange" , "Pear"   # Access the first element of the array using index 0. $Fruit [ 0 ]   # Access the second element of the array using index 1. $Fruit [ 1 ]   # Access the last element in an array using -1. $Fruit [ -1 ]   # Access the last element in an array using -2. $Fruit [ -2 ] OK, that was easy. Not so for the next two.   Using Script Blocks { } The curly braces are used with script blocks. A script block allows you to take multiple lines of code and use them as a single unit. Many commands can utilize script blocks. S