Thursday, July 25, 2013

PowerShell: Downloading CSV's from SCCM-SMS 2007 Reporting Websites

I needed to bundle the SCCM/SMS 2007 ConfigMgr web reporting results into PowerShell or Excel.  The SMS Web Reporting has a great export-to-CSV tool on each page but runs Java in the background and requires a confirmation click and a subsequent filename before being able to download the CSV file.  Once downloaded, it quickly becomes a PowerShell object via import-csv.  After lots of searching, I compiled a method to automatically download and save the CSV file so it can be used by PowerShell.


#Set the variables

$xhttp = $nul
$stream = $nul
$username = "domain\username"
$password = "password"
$url = 'http://sccmserver/SMSReporting_bob/Report.asp?ReportID=386&Name=MyPcName'
$destination = "c:\users\myname\desktop\MyPcName.csv"

#Start XML

$xhttp = new-object -com msxml2.xmlhttp

$xhttp.open("Post",$url,$false,$username,$password)

$xhttp.setrequestheader("Content-Type","application/x-www-form-urlencoded")

#this sends the request to perform a CSV export

$xhttp.send("export=yes")

#This line's not needed but I use it to get confirmation
#that the download is queued correctly.  If not OK then
#I know to check the above part of this script

$xhttp.statustext

#Now grab the file in the buffer and save it to disk

$stream = new-object -com ADODB.Stream

$stream.open()

$stream.type = 1

#Connect the buffer to the downloaded file

$stream.write($xhttp.responsebody)

$stream.savetofile($destination,2)

$stream.close()

$stream = $nul

References:
http://myitforum.com/cs2/blogs/jnelson/archive/2008/04/02/114527.aspx
http://www.greyhathacker.net/?p=500
http://scriptolog.blogspot.com/2007/08/query-http-status-codes-and-headers.html

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.