Lessons Learned

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

June, 2011

Posts
  • 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

    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...
  • 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

    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

    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

    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 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

    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

    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

    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

    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

    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

    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

    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...
Page 1 of 1 (14 items)