Friday, May 27, 2011

Powershell Arrays

1) How do I create a dynamic array
$a = @()

2) How do I append an element to array
$a += "a"
$a += "b"

3) how do I do a UBOUND on an array
.NET array indexes are zero-based, so ubound is length-1:
$a.length - 1

Monday, May 23, 2011

Powershell - Using IE

Have successfully using Powershell to access IE. Trick to be aware of.
If you launch a web page using "New-Object -comObject InternetExplorer.Application", UAC will block you from accessing the document properties inside. Use the following technique:

  & "$env:programfiles\Internet   Explorer\iexplore.exe" 'http://powershell.com'
  $win = New-Object -comObject Shell.Application
  $try = 0
  $ie2 = $null
  do {
    Start-Sleep -milliseconds 500
    $ie2 = @($win.windows() ? { $_.locationName -like '*PowerShell*' })[0]
    $try ++
    if ($try -gt 20) {
      Throw "Web Page cannot be opened."
    }
  } while ($ie2 -eq $null)
  $ie2.document
  $ie2.Document.body.innerHTML

Monday, April 18, 2011

Dunning-Kruger effect

An interesting read. "The unskilled suffer from illusory superiority, rating their ability as above average, much higher than it actually is, while the highly skilled underrate their own abilities, suffering from illusory inferiority."

http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect

Another homorous way of saying this is that if you are an optimist, then you don't have all of the information.

CSVDE Command Syntax

I learned today how to query AD from the command line to list only active servers. The filter includes the conditions "not disabled" and also "not an EMC Celerra"

csvde -f output.csv -r "(&(objectClass=computer)(!(userAccountControl=4098))(&(operatingSystem=*server*)(!(operatingSystem=EMC Celerra *))))" -l displayName,operatingSystem,operatingSystemVersion,operatingSystemServicePack,name,cn,dNSHostName