Lessons Learned

My drop-site for interesting snippets and tips. If it's useful to you as well, great!

July, 2011

Posts
  • Lessons Learned

    Why Use Semi-colons

    • 0 Comments
    I get asked from time to time why I still put semi-colons at the end of each statement. Part of it is force of habit. Part of it is trying to make sure my script source is useful no matter how the web server, post edtior, and user's brower decide to display...
  • Lessons Learned

    Abbreviated Key Names in Synthetic Properties

    • 0 Comments
    The title is almost longer than the post. From Chris Dent's http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/ , I see that he's generating synthetic properties with Select-Object -Property @{n = 'name'; e = { "this...
  • Lessons Learned

    A Loop of One

    • 0 Comments
    Of late, I've been seeing some of my scripts do this: if (!(Test-Path file1)) { Write-Warning "File1 not found."; } else { do-something if (!(Test-Something)) { Write-Warning "Test-Something failed"; } else { do-something -part 2 if (!(Test-Something...
  • Lessons Learned

    PowerShell and IIS Logs

    • 0 Comments
    This is more of a pointer than an actual article. Chris Dent at www.intended.co.uk has a great post on getting IIS log settings from hosts here: http://www.indented.co.uk/index.php/2010/01/12/powershell-iis-and-log-settings/ The best part is how...
  • Lessons Learned

    Getting Objects Out of AD

    • 1 Comments
    This is dsquery.exe computer -name <foo> function Get-ComputerObjects { param ( [string] $name = "*" ); $directorySearcher = new-object DirectoryServices.DirectorySearcher([ADSI] "LDAP://$env:userDnsDomain" ); $directorySearcher .PageSize...
  • Lessons Learned

    PSH V1 or V2?

    • 1 Comments
    My lab has some machines that are only running PSH v1 (for reasons outside the scope of this article.) The easiest way is to try to run something that exists on V2, such as "import-module". However, the progamatic way is to get the ProductVersion property...
  • Lessons Learned

    XPath and attribute value strings

    • 0 Comments
    Quick note for my future reference - XPath1.0 evidently doesn't support wildcards nor regular expressions, but does have functions such as 'starts-with', 'contains', etc. $xml.SelectNodes("//nodeName[contains(@attribute, 'substring')]"); http:/...
  • Lessons Learned

    Scanning for Binaries and Version

    • 0 Comments
    I need to list the binaries installed to a folder and below for the software I’m testing. I can do that with Get-Command on each one, but this allows me to do it recursively and automagically. function Get-LocalBinaries { param ( [string[]] ...
  • Lessons Learned

    Testing a Port

    • 0 Comments
    Load blancers are great, but we don't get iAdmin access to them, so the only way we know if a host is down is to visually scan the web UI. And for whichever EIEIO security standard, we have two-factor auth which times out after a very aggressive interval...
  • Lessons Learned

    Ignoring SSL Certificate Errors with WebClient

    • 0 Comments
    First off, credit where credit's due. The incomparable Lee Holmes first tackled this in his blog: http://www.leeholmes.com/blog/2007/03/19/converting-c-to-powershell/ But I couldn't get it to work. Then I found Bhargav Shukla's method http://blogs...
  • Lessons Learned

    "Manage Your Server" Welcome Screen

    • 0 Comments
    Yeah, I'm still running 2003. In fact, I'm still asking the lab admins to build out new 2003 boxes. And when I log onto them, I get that next-to-useless "Manage Your Server" box. Here's how to blow it away in a cmd.exe or PowerShell.exe window: ...
  • Lessons Learned

    Remotely Logging off RDP Sessions

    • 1 Comments
    In our lab, we don't have Terminal Services Licensing set up. This means our servers have only 2 logon sessions per host. We have a GPO in place to log off non-console sessions after 24 hours of idle time, but we also have tradition of playfully chiding...
  • Lessons Learned

    2>NUL in PowerShell

    • 0 Comments
    We can have PowerShell eat an .exe's STDOUT very easily: xcopy file.txt target.txt | Out-Null; We can have it eat both STDOUT and STDERR by redirecting STDERR into STDOUT xcopy file.txt target.txt 2>&1 | Out-Null; xcopy "ThisFileDoesn...
  • Lessons Learned

    Don't Do This: PSExec'ing a Batch Script Containing a PowerShell Script

    • 1 Comments
    This is just broken, but broken times call for broken measures. I'm stuck on PSH V1 for reasons best left unmentioned (or maybe it's unmentionable reasons.) To run remote commands, I don't have remoting at my disposal - I'm stuck with SysInternal's PSExec...
  • Lessons Learned

    PowerShell for Unix's "data | sort | uniq -c" and "sort -u"

    • 0 Comments
    Sometimes we need a list of data values and their frequency. Other times, we need a unique listing of data values. Under Unix, 'sort -u' gives a unique listing of values from STDIN, and 'sort | uniq -c' gives a listing of unique values and their frequencies...
  • Lessons Learned

    Number of Processors vs. Number of Cores

    • 3 Comments
    In this day of multicore, multiprocessor systemboards, licensing becomes a little more complicated. Some packages are licensed per core, others per processor. Still others are licensed per n cores per processor. At any rate, Win32_Processor doesn't return...
  • Lessons Learned

    Is Oracle WebLogic10 Installed?

    • 2 Comments
    We have a handful of boxes running WebLogic10 so it's not part of the base image. Here's a quick way to determine if it's installed. $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $myComputer); $subKey= "SOFTWARE\Microsoft...
  • Lessons Learned

    Test if IIS6 installed and .NET 2.0 Registered?

    • 0 Comments
    Easier question first: is IIS installed? $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $myComputer); $subKey= "SYSTEM\CurrentControlSet\Services\W3SVC" -replace '\\', '\\'; if (!($reg.OpenSubKey($subkey))) { Write-Warning...
  • Lessons Learned

    Is East Asian Langauges Pack Installed?

    • 0 Comments
    (Note: This is relevant only for XP and prior, which our lab still has.) If we test for "HKLM\SOFTWARE\Classes\IMECheckDefaultInputProfile.Japan" (using Japanese as an example), we can tell if the East Asian Language pack is installed. $reg = [Microsoft...
Page 1 of 1 (19 items)