Skip to main content

Posts

Showing posts from June, 2013

powershell: reducing processing time (niche case)

why the caveat? it's important to note that my savings is based on switching out just a simple little thing. there's no magic here. there's no fountain of knowledge. those accolades are for the likes of snover and wilson. BACKGROUND the synopsis is simple. i was asked to create a very specific user list. the specifications were such that i had to consider custom objects to store the information. here are the requirements: must be a csv formatted file must have headers that match a specified string must contain columns even if the value is empty must decode the manager dn to the manager's employee id after spending a little time getting formatting right, i realized that performance was just terrible. i admit i created it in the laziest way possible. i mean that is what scripting is about right? saving time?  DEFINING CRAZY for processing a thousand users and creating a thousand custom objects, it was okay since the span of time was relatively short. when

powershell: retrieving warranty data

...or as dell would say ... "entitlements". first of all, check this out:  http://xserv.dell.com/services/assetservice.asmx . dell has a webservice that you can use to pull down warranty information on your system. there are three arguments you have to provide to make this work: guid application name service tag the only key piece of information is the service tag. the other two arguments will accept any piece of data as long as it's the right type. let's examine each of these for a quick second. guid the easiest way to generate a guid is by using the newguid() method as such: $guid = [guid]::parse("11111111-1111-1111-1111-111111111111") application name set this to whatever string value strikes your fancy. (do people say that anymore?) service tag this is the part actually drives the context. provide your service tag (some call it asset tag, some call it serial number, etc) as the third argument and away you go. if you want to pul

powershell: an array of alphabets

i wish i could remember where i found this particular gem. as you know, it's crazy easy to create an array of values if they're integers such as: [1] {C:\temp} > $a = 1..10 [2] {C:\temp} > $a 1 2 3 4 5 6 7 8 9 10 but what about when you want an array of alphabetical characters like a through z? it's not as simple as defining the range as a..z. instead, you have to call the char type as shown below: [7] {C:\temp} > $alphabet = [char[]]([char]'a'..[char]'z') [8] {C:\temp} > $alphabet a b c d e f g h i j k l m n o p q r s t u v w x y z

powershell: retrieving directories in the current path

hard -- obscure if you don't know the calls, aren't familiar with programming (basically, me) [io.directory]::GetDirectories($(get-location)) medium -- not so bad when you know what to look for get-childitem | where-object { $_.mode -eq "D----" } get-childitem | where-object { $_.PSISContainer -eq $true } get-childitem | where-object { $_.Attributes -eq 'Directory' } easy -- at least there's no bracketing or positional parameters to worry about get-childitem | where-object psiscontainer -eq $true easiest -- near parity with cmd shell, provided you use shortcuts get-childitem -directory