Lessons Learned

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

Posts
  • 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...
  • Lessons Learned

    Is .Net 3.5 Installed?

    • 2 Comments
    A quick-and-dirty way to determine if .NET 3.5SP1 is installed. $path = "\\$myComputer\c$\windows\Microsoft.NET\Framework\v3.5\csc.exe"; if((Get-WmiObject -ComputerName $myComputer -Query "select * from Win32_OperatingSystem").OsArchitecture -eq '64...
  • Lessons Learned

    Is NetBIOS over TCP/IP Enabled?

    • 0 Comments
    As anyone who has typed 'ipconfig /all' knows, Windows has a lot of pesudo- and otherwise irrelevant network adapters that exist only as 'logcal entities'. The clause 'where IPEnabled='true'" will separate out the true TCP/IP adapters, but in some cases...
  • Lessons Learned

    System Variables on Remote Machine

    • 0 Comments
    To get the $env:PATH system variable value on a remote machine. $path = Get-WmiObject -computerName $myComputer -query "select * from Win32_environment where username='<system>' and name='path'"; To update it setx.exe -s $myComputer -m...
  • Lessons Learned

    Stupid PSH Trick: Diffing Lists

    • 0 Comments
    I have two lists of strings. One contains values that must be in the output. The other is the actual output, Split() into strings. I need to ensure all elements in the first list are in the second. Optionally, I may need to ensure the second list only...
  • Lessons Learned

    My Way of Logging Problems: Log-Problem

    • 0 Comments
    Write-Error is fine, but there's no way to capture it in redirect. This means that a script peppered with 'Write-Error' will show nothing if redirected to a file. The only way to capture it is to Start-Transcript. Some people use $error only for what...
  • Lessons Learned

    Playing with Window Size

    • 0 Comments
    $host isn't just for EnterNestedPrompt(). $host.UI.RawUI has some intresting data. For example, Nicely Wrapping a Line of Text to STDOUT uses $host.UI.RawUI.WindowSize.Width to determine where to break the line based on window width. However, $host...
  • Lessons Learned

    User Names, SIDs and Active Directory

    • 0 Comments
    Let's go backwards. We figured out how to get a user name out of a SID earlier: [ adsi ] "LDAP://<SID=$sid>" How do we get the SID from a user name? It turns out that's not quite as easy: $ntAccount = new-object System.Security.Principal...
  • Lessons Learned

    Auditing Forefront Endpoint Protection 2010's Exclusion List

    • 0 Comments
    Disclaimer: I can't be sure this works for all exclusion scenarios. My lab machines are set up to use this regkey, but manual tests have shown other regkeys. # Forefront exclusion list $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine...
  • Lessons Learned

    Getting Web Proxy Settings

    • 1 Comments
    We have a lab of hosts that have proxy exclusion lists set at various times in the lifecycle of the lab, so they have slightly varying values. We'll build on the REG_BINARY to [string] trick with this: function Get-WinHttpProxy { param ( [string...
  • Lessons Learned

    Stupid Tricks with REG_BINARY Registry Data

    • 1 Comments
    This is one of those 'duh' moments. [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('HIVE', $computer).OpenSubKey($subKey) returns REG_BINARY data as an array of [byte]. To convert to [string]: [string]::Join($null, ($regBinaryData | % { [char...
  • Lessons Learned

    SID, User Names, and Active Directory

    • 0 Comments
    More of a snippet for me to refer to later, but here's a quick way to convert a SID (Security Identifier) to a user's name in AD: PS D:\> $sid = 'S-1-5-21-3160822684-348306091-3778041397-7630' PS D:\> [adsi]" LDAP://<SID=$sid >" distinguishedName...
  • Lessons Learned

    Nicely Wrapping a Line of text to STDOUT

    • 0 Comments
    In case you didn't know, $host gives data about the scripting host, including the window containing the script's output. This in turn gives us the width of the window: $Host.UI.RawUI.WindowSize.Width From there, we can function Break-Line { ...
  • Lessons Learned

    PowerShell, Downloaded Scripts, and Alternate Data Streams

    • 0 Comments
    First off, here are the sources for this article: http://www.hanselman.com/blog/RemovingSecurityFromDownloadedPowerShellScriptsWithAlternativeDataStreams.aspx http://thepowershellguy.com/blogs/posh/archive/2007/01/27/powershell-accessing-alternative...
  • Lessons Learned

    Pinging a Hostname with Timeout

    • 1 Comments
    Well, that's simple: $ping = New-Object System.Net.NetworkInformation.Ping; [ bool ]( $ping .Send( $computer , $pingTimeout ).Status -ne 'Success' ); It gets more interesting when we need to verify that $computer is actually valid. We can use [System...
Page 7 of 9 (213 items) «56789