Tuesday, July 8, 2014

Modify multiple Active Directory Accounts with PowerShell

Has you company recently moved to a new location? If so here is a script to modify the "StreetAddress" Active Directory attribute for multiple users at once.
Import-Module ActiveDirectory
 $users = $i = $null
 $users = Get-ADUser -filter * -property StreetAddress
 ForEach($user in $users)
  {
   if([string]::isNullOrEmpty($user.StreetAddress))
    {  
      "modifying $($user.name)"
      Set-ADUser -Identity $user.distinguishedName -StreetAddress "1600 Pennsylvania Ave NW"
      $i++
    }  
 }  

This could be used to modify any of the Active Directory attributes by simply editing the -property being queried.

PowerShell function to modify Active Directory IP Phone Attributes

I follow many different PowerShell Scripting blogs and discussion groups, today someone said to the group, "I need to Update AD Attribute (IP Phone) for Bulk Users at a time."

Here's what I came up with;

<#
.CREATED BY:
    Matthew A. Kerfoot
.CREATED ON:
    07/08/2014
.SYNOPSIS
   create and set IP Phone number in AD
.DESCRIPTION
   This function will create and set the IP Phone attribute in Active Directory per user specified.
.EXAMPLE
   Set-IPPhone -username mkerfoot -New_IP_Phone_Number 555-555-5555
#>

 function Set-IPPhone { 
                        [CmdletBinding()]
                Param ( [Parameter(Mandatory=$true,
                        ValueFromPipelineByPropertyName=$true,
                        Position=0)]
                        $username,
                        [Parameter(Mandatory=$true,
                        ValueFromPipelineByPropertyName=$true,
                        Position=0)]
                        $New_IP_Phone_Number )

 Begin { import-module activedirectory }

 Process { 
 
            $user = Get-ADUser -identity $username | Foreach-Object { $lookup = "LDAP://" + $_.DistinguishedName;[ADSI]$lookup}

            $user.put("IPPhone","$New_IP_Phone_Number") 
         }

 End { $user.setinfo() }

 } Set-IPPhone

Thursday, April 24, 2014

Cleanup a D:\ Drive

     Have you ever had the pleasure to clean up a full D:\ drive? If yes, you know this can be a pretty daunting task. If No, just know that you need to be very careful with any data saved on any Volume C:\ through Z:\. Any Volume other than C:\ usually contains data that is irreplaceable weather it has backups saved on it or SQL data that is needed to keep a business running.
   As you can see to the left TreeSizeFree is showing that there are 20.6 GBs of data being stored in a folder called System Volume Information (SVI). By default this folder will be hidden so you must first show all hidden system files with either a CMD prompt or PS prompt this can be done quite easily.
CMD
dir D:\ /AH
PowerShell
Get-Childitem -Force
Next type "vssadmin list shadowstorage" to find the loaction and size information of the SVI folder.

vssadmin list shadowstorage
After you know the location of the SVI folder you can change the MaxSize of the System restore files
vssadmin resize shadowstorage /For=D: /On=D: /MaxSize=5GB
From 3% to 12%.