Friday, July 25, 2014

Happy Sys Admin Day!

Star Wars Theme Song with PowerShell


In celebration of Sys Admin Day I bring to you the Star Wars theme song via PowerShell!

Enjoy!


[console]::beep(440,500)       
[console]::beep(440,500) 
[console]::beep(440,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,1000) 
[console]::beep(659,500)        
[console]::beep(659,500)        
[console]::beep(659,500)        
[console]::beep(698,350)        
[console]::beep(523,150)        
[console]::beep(415,500)        
[console]::beep(349,350)        
[console]::beep(523,150)        
[console]::beep(440,1000)



Oh and don't forget to buy your Sys Admin a beer.



All Sys Admins Like beer! 

Tuesday, July 8, 2014

Super Mario Theme Song with PowerShell

Here's a little PowerShell script that plays the Super Mario Theme Song!!
I hope you enjoy this as much as I enjoyed making it!!
<##Super Mario Intro ##>
$i = 1
do {$i++
        [console]::beep(659,250) ## E
        [console]::beep(659,250) ## E
        [console]::beep(659,300) ## E
        [console]::beep(523,250) ## C
        [console]::beep(659,250) ## E
        [console]::beep(784,300) ## G
        [console]::beep(392,300) ## G
        [console]::beep(523,275) ## C
        [console]::beep(392,275) ## G
        [console]::beep(330,275) ## E
        [console]::beep(440,250) ## A
        [console]::beep(494,250) ## B
        [console]::beep(466,275) ## A
        [console]::beep(440,275) ## A
        [console]::beep(392,275) ## G
        [console]::beep(659,250) ## E
        [console]::beep(784,250) ## G
        [console]::beep(880,275) ## A
        [console]::beep(698,275) ## F
        [console]::beep(784,225) ## G
        [console]::beep(659,250) ## E
        [console]::beep(523,250) ## C
        [console]::beep(587,225) ## D
        [console]::beep(494,225) ## B
   }until ($i -gt 1)

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