Wednesday, March 20, 2013

PowerShell: Remove Computer Object from Active Directory (or modify object properties)


This technique bypasses the need to load the Active Directory module and has been tested in PowerShell 2.0 & 3.0.  The CN= reference can be either a computer or user.  This script connects to your domain and searches for an object you assign via the variable $oldcomp.  You can also change the objects properties once found in AD.  That's described in the second part of the script.

#Grab your local domain for ADSI

$searcher = [adsisearcher][adsi]""

#Create $oldcomp however you like then use it as input for the ADSI searcher

$searcher.filter ="(cn=$oldcomp)"

#Search Active Directory for the current location of the computer object

$searchparm = $searcher.FindOne()

#Assign $deleteoldcomp to the found path

$deleteoldcomp = $searchparm.path

#Assign the ADSI object to a variable

$delcomp = [adsi]("$deleteoldcomp")

#I used the Try/Catch sequence in case the computer wasn't found in AD.
#the deletetree() removes the object from the domain, not the computer 
#itself.  Stop here if you only want to find the object and then edit its 
#properties.  If you wish to delete it, then add this next line:

try {$delcomp.deletetree()}catch{}

After you have found the computer object, you are able to edit its properties.  If you take the $delcomp object and type $delcomp|format-list * then you'll see information about your object.  To change your computer object properties:

#To change the computer description property

$delcomp.description = [string]"Whatever String Value you want"

#To assign a technician in the ManagedBy property, copy/paste the 
#technicians user object

$delcomp.managedby = "CN=TechnicianUserID,OU=..."

Use the same technique to assign other property values.  When you are finished, you'll need to save your changes back to the computer object.  Ensure your account has the correct credentials.

$delcomp.setinfo()


Wednesday, March 13, 2013

Futurology: Weaning Humans Off Death

This stunning illustration summarizes how death occurred during the 20th century.  With numerous advances in the medical/technological fields, we'll see a vast reduction of health-based deaths in the 21st Century.  Already there are great strides taken to create 3D printed replacement tissue and organs.  We can convert skin cells into stem cells and use them to repair body components.  Combined with technological breakthroughs with nanobiotics, the likelihood of dying from "natural" causes will dwindle as the century advances on.  It is my hope that these advances will motivate societies to quit destroying each other (or themselves) and focus on humanity and the advancement of it.

Visit Data is Beautiful for more information about this chart.

Sunday, March 10, 2013

Hardware: Self-healing Circuit Boards

Phys.org has a great article about an awesome Cal-Tech breakthrough:  Self-healing circuit boards. Capacitors, resistors, and other electronics will be able to recover from power spikes or brown-outs, getting wet, over heated, or any other type of injury capable of ruining your device or system.  All we need is artificial intelligence (Watson anyone), and a self-sustaining power source and these entities will be our Frankenstein creatures!  What can possibly go wrong?  (/end tangent)

Can you imagine the crossover abilities of incorporating this technology into the biological 3D printer advancements?  Creating self-healing human body parts via nanobots.  Wow, exciting times lie ahead for both humans and their electronic companions.



A quote from the Phys.org article:
"It was incredible the first time the system kicked in and healed itself. It felt like we were witnessing the next step in the evolution of integrated circuits," says Ali Hajimiri, the Thomas G. Myers Professor of Electrical Engineering at Caltech. "We had literally just blasted half the amplifier and vaporized many of its components, such as transistors, and it was able to recover to nearly its ideal performance."

Read more at: http://phys.org/news/2013-03-caltech-self-healing-electronic-chips.html#jCp

Interfaces: New Advances

On May 13th, 2013, Leap-Motion begins selling their new computer interface which will boost Windows 8's market share.  There's no surprise Microsoft envisioned a touch-based interface when designing Metro.  Where Microsoft went wrong is not taking advantage of their XBOX360 Kinect product.  They missed an opportunity to lead the market on gestural input designs.  Instead, developers hacked the product and created their own solutions.  Microsoft finally created an SDK but after the horse had bolted.  Microsoft should have bundled a Kinect-like device with Windows 8 and capture this new interface market.

Leap-Motion's fledgling company developed a simple, robust, and cheap device capable of accurately registering hand and finger movements.  I predict this device will expand and become a de facto interface integrated into the next generation of computers, phones, and other devices which would benefit from hands-free movement-based interactions.  Watch these two videos to get an understanding on how simple yet accurate the controller is and you'll agree how instrumental it'll be in future devices.  I'd love to see it embedded into Google-Glass.

Saturday, March 2, 2013

PowerShell: Music Files, Get-Hash, and creating filtered folders

As music files are collected, it can be found that some files will have exact names even though the songs may be different versions.  Another problem is getting exact duplicate songs with different file names.  I created a script which filters both scenarios and moves one file-hash-based copy of exact files to a new folder structure based on the Artist name -- leaving hash duplicates in the original folders.  If a second exact-named but not a hash-duplicate file attempts to move into the Artist's folder, the script makes a subfolder named after the files hash then moves the file to it.  

I've only tested this script using PowerShell 3.0.
Disclaimer: This script will create new folders and move files from their original location to new ones.  Script errors can result in misnamed files.

I'll explain more as we go over the script:

#Taglib is described in my previous blog
#Click here to learn how to install this ID3 tag utility

$taglib = "C:\PowerShell\taglib\libraries\taglib-sharp.dll"
[system.reflection.assembly]::loadfile($taglib)|out-null

#Select the destination root folder where you want 
#your processed files to go. Make sure to leave the
#trailing backslash

$destination = "e:\hash3\"

#The hashtable variable will gather all your music files from the 
#current folder and all subfolders and process their hash strings.
#Click here to learn how to install Get-Hash

$hashtable = gci -file -recurse -include *.flac,*.ape,*.ra,*.m4a,*.mp2,*.wma,*.mp3|get-hash

#We add a new Hashtable property for the incoming Artist object and
#assign an empty value "" as placeholder

$hashtable|add-member -membertype noteproperty -name Artist -value ""

#Now we select each file in the hashtable and resolve the 
#artists name.  If the file is not a valid music file, we
#write the error file name to the console and add it to a
#text file with other invalid files.

foreach ($a in $hashtable){

$fileperformers = $nul

$filealbumartists = $nul
$fileartist = $nul
$albumartist = $nul

#Here's the try/catch for the taglib which is trying to load
#the ID3 file values.  If it finds any ID3 errors, it'll move the file to 
#an "invalid Audio File"\hash-string subfolder.


try{
$media = [taglib.file]::create($a.path)
}
catch [exception]{
write-host -foregroundcolor "yellow" ($a.path + " - invalid audio file")
$a.path|out-file c:\powershell\hasherrors.txt -append
$fileartist = "Invalid Audio File"
if (!(test-path ($destination+$fileartist+"\"+$a.hash))){md ($destination+$fileartist+"\"+$a.hash+"\")}
move $a.path ($destination+$fileartist+"\"+$a.hash+"\")
}

#We pull the Artist name and filter brackets and untypical characters



$fileartist = $media.tag.performers
if ($fileartist){
$fileartist = $fileartist -replace ("\[","")
$fileartist = $fileartist -replace ("\]","")
$fileartist = $fileartist -replace ("[^0-9a-zA-Z-&\']"," ")
}

#Next we pull the Album Artist name and process it

$albumartist = $media.tag.albumartists
if ($albumartist){
$albumartist = $albumartist -replace ("\[","")
$albumartist = $albumartist -replace ("\]","")
$albumartist = $albumartist -replace ("[^0-9a-zA-Z-&\']"," ")
}

#We see if the performers tag was a real value
#if not, we try to use the album artist value
#if no performer or album artist value, we use "Unknown"

if (!$fileartist){$fileartist = $albumartist}
if (!$fileartist){$fileartist = "Unknown"}

#We enter the result into the added Artist object

$a.Artist =$fileartist
}

#We sort the resulting hash table by unique hashes
#this gives us a list of unique hashes, leaving duplicates
#behind

$hashtable = $hashtable|sort hash -unique


#We create new destination folders, check for exact file names
#in the new folders, and if exist, then create hash-named folders
#and place the file into it
#we also bypass error files which have already been moved

foreach ($h in $hashtable){
if (!(test-path $h.path)){continue}
if (!(test-path ($destination+$h.artist))){md ($destination+$h.artist)}

if ((test-path ($destination+$h.artist+"\"+$h.path.split('\')[-1]))){
md ($destination+$h.artist+"\"+$h.hash)
move $h.path ($destination+$h.artist+"\"+$h.hash)}

if (!(test-path ($destination+$h.artist+"\"+$h.path.split('\')[-1]))){move $h.path ($destination+$h.artist)}
}