Lessons Learned

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

Posts
  • Lessons Learned

    Getting Computer Memory Usage

    • 0 Comments
    Here’s a quick spot-check on the memory usage on remote computer (or a few dozen computers).  It uses WMI objects – Win32_ComputerSystem for the TotalPhysicalMemory and Win32_OperatingSystem for FreePhysicalMemory, TotalVirtualMemorySize (why did...
  • Lessons Learned

    Fun with PSCredentials

    • 0 Comments
    Back in October of 2012, I posted Securely Storing a Password , which showed the key commands to capture a password and store it as a SecureString in a file. However, this doesn’t address using that password as a PSCredential. Let’s remedy...
  • Lessons Learned

    Converting PsCustomObject To/From Hashtables

    • 3 Comments

    Functions to converting Hashtables to PsCustomObjects and vice versa (losing all PsCustomObject class members that are not properties such as noteproperty).

    ...
  • Lessons Learned

    AppWiz.cpl in PowerShell

    • 0 Comments

    Querying the registry for installed programs remotely

    ...
  • Lessons Learned

    PSH V1 Get-Tail

    • 0 Comments
    In PSH V2, Get-Content –Tail 10 –Wait will display the last 10 lines of a file, then poll it every second and display any additions to it. In PSH V1, Get-Content didn’t have a –Tail flag, so if you wanted to do the equivalent of...
  • Lessons Learned

    Get-FileVersion

    • 0 Comments
    With an endless stream of daily builds, it is essential that a test lab run the latest version.  PS C:\Users\timdunn> dir C:\Windows\System32\*.dll | Get-FileVersion | more Path                                                       ...
  • Lessons Learned

    Getting An SSL Web Page’s Certificate

    • 0 Comments

    When it comes time to rolling SSL certificates on web servers, nothing beats checking the server to see what is actually being served.

    ...
  • Lessons Learned

    SQL Fun(ctions)

    • 0 Comments

    To start with, a disclaimer: I’m not a SQL person.  No, not at all.  I just find myself supporting services that use MSSQL as a backend.  Here are a few functions I’ve recently written to help keep my sanity.

    ...
  • Lessons Learned

    Removing Null Values

    • 0 Comments
    How many times have you gotten a WMI-Object and had to scroll through screens of null values? Here's a quick way to generate a new PSCustomObject that has those values removed. Note that this is NOT the same object type as the input object, and it does...
  • Lessons Learned

    Another Way to Create NoteProperty Entries

    • 0 Comments
    We've seen the Select-Object synthetic property method and the Add-Member -name AddNoteProperty method, but here's probably the most straightforward way to output object data. $object = $true | Select ComputerName, Path, ContentCount; $object.ComputerName...
  • Lessons Learned

    Securely Storing a Password

    • 5 Comments
    Here's the scenario: You have a script that needs to access a static password which has to be stored in a file, but you do not want the password readable. Here is a way to encrypt the password so that only you can read it. Anyone else running the same...
  • Lessons Learned

    Why Semi-Colons?

    • 0 Comments
    Sorry, no code here. Just a quick thought. Q: Why should I put semi-colons at the end of lines? PowerShell is smart enough to parse EOL as command terminators. A: Because some blogs are stupid and strip linefeeds. That means you get a single line...
  • Lessons Learned

    Laziness and XML: New-XmlElement

    • 0 Comments
    I love structured data. I love how orderly it is, how logical. However, I do not like the repetition. Get the OwnerDoc. Create an Element. Loop over a bunch of AddAttribute calls, AppendChild it someplace. 90% of the time, this is how I build my XML structure...
  • Lessons Learned

    Out-Error, the User-friendlier Write-Error

    • 0 Comments
    Write-Error is a pretty daunting cmdlet. It dumps some pretty useful information to screen. Useful, that is, for the scripter. For the non-PowerShell-guru end user, it can be pretty intimidating. Write-Host -ForegroundColor Red might be a better...
  • Lessons Learned

    One-Liner: Dotting in vs. Running a Script

    • 0 Comments
    PowerShell scripts are a collection of functions and procedural code, right? So often, I find myself wishing I had a function defined in a script in my interactive session, but the script doesn't lend itself to being dotted into the environment. if...
  • Lessons Learned

    Getting OCS 2007 Certs through WMI

    • 0 Comments
    We recently had an interesting adventure where we needed to do an audit of the certificates used by various OCS servers. In this case, scanning the computer's cert store wasn't sufficient - we needed to see which cert was bound to what interface. The...
  • Lessons Learned

    Creating a Multi-Host Cert MMC

    • 0 Comments
    MMCs are a mixed blessing at best. The saved .msc files aren't human-editable (read: not XML) so I don't have an easy way to create them. In this case, I need to perform a cert audit on all the machine certs in a lab. PowerShell eschews 'parsing by prayer...
  • Lessons Learned

    Dumping ILO (and Other DHCP Addresses)

    • 0 Comments
    Here's a quick-n-dirty script that dumps ILO address from the DHCP server. function Get-Ilo { param ( [ string ] $computer = $env:COMPUTERNAME ); $scope = (netsh.exe dhcp server \\$computer show scope | Select-String 'ilo' ) -replace "\s+-.*" -replace...
  • Lessons Learned

    RSA Authentication Manager User Auditing

    • 0 Comments

    RSA Authentication Manager exports the list of users and SecurID fobs in a text format with multiline records.  Moreover, if the user does not have a SecurID, the number of fields displayed is truncated.  Fortunately, .CSV will gladly accept 'short' records.  Here is a way to convert the User.DMP file that lists all users in the RSA Authentication Manager DB, and their fobs if present.

    ...
  • Lessons Learned

    Clock Skew and You

    • 0 Comments
    We had an issue where the clocks on various hosts got offset beyond the margin allowed by an application we were testing. Here's a way to scan hosts for their clock skew relative to a known good server: function Get-RemoteTime { param ( [ String [...
  • Lessons Learned

    Set-ExecutionPolicy Fun

    • 0 Comments
    Hm, I'm surprised this isn't included Out-Of-The-Box. Let's say I have a new deployment of machines and I need to set the ExecutionPolicy for each of them. Now, assuming I'm a domain admin, I should be able to do it remotely: Function Enable-PowerShell...
  • Lessons Learned

    Accessing Performance Counter (for OCS A/V Edge Servers)

    • 0 Comments
    OCS A/V Edge servers are somewhat wierd critters. One interface is load balanced, the other is accessed only by the trusted server list. The Load Balancer should be able to display the number of connections, but what about the internal interface? Say...
  • Lessons Learned

    Batch-Unzipping Files

    • 0 Comments
    Thanks to http://serverfault.com/questions/18872/how-to-zip-unzip-files-in-powershell/201604#201604 for the core code. Here's a function to unzip files, with rudimentary error handling, and ability to specify source and destination from the command...
  • Lessons Learned

    Displaying an OCS Proxy Server's List of Trusted Servers

    • 0 Comments
    Yesterday, we covered how to dump an OCS Edge Server's list of trusted servers, including using PSExec.exe as a workaround to it not exposing the list over remote WMI calls. It turns out the OCS Proxy Server uses a different WMI path, but it can be...
  • Lessons Learned

    Displaying an OCS Access Edge Server's List of Trusted Servers

    • 0 Comments
    Office Communications Server's Access Edge Servers and MediaRelay roles have a list of hosts they allow to connect on the internal interface. This is managed by the an administrative GUI accessed under ComputerManagement. GUIs are great for discoverability...
Page 4 of 8 (178 items) «23456»