Thursday, July 9, 2015

PowerShell: Export-CSV with specific user info

Today I had need to export a bunch of info about our users for some sort of internal survey sending situation.


Get-ADUser -Filter * -SearchBase "OU=Employees,DC=Domain,DC=Com" -Properties DisplayName, EmailAddress, Department, Manager | Select DisplayName, EmailAddress, Department, Manager | Export-CSV "D:\path"

GT rebuild: Sears ST/16 Part 2

So one of the very first problems I ran into on this build was the engine smoked like a freight train.  The previous owner said he thought it needed piston rings.  I ran able to get it started and drove it around the yard twice and I noticed two things: A. The head gasket was blowing oil onto the back of the muffler and B. Yes lots of smoke comes out of the muffler itself.

I checked, and double checked and triple checked the valve clearance and the .006 intake and .010 exhaust is set correctly. The starter, sheet metal, valve train, and SSI were all good.

Being as the ring kits were upwards of $60 bucks, and I lack the tools to remove the rockers and valves I decided to re-power.

Lucked into a nice guy on Craigslist who had a Tecumseh OH140 14hp engine, with a bad SSI.  Since I had a known good one I figured it'd be a good buy. We tested the starter before exchanging money and it turned over very well, which mine did not.  So I bought it and brought it home.

I spent quite a few days cleaning the new engine. and then putting on and testing the SSI swap.  Now what I don;t know is, at some point during the SSI testing I somehow either killed mine or it just stopped working. Damn.  Replacement SSI units even on eBay run almost $250!  No way would I spend that kind of dough on it so in my many googling sessions I stumbled across Ed Stoller's website about converting SSI ignitions into coil/battery setups.
Engines and Magnets

Of Note: Be careful scraping off the existing epoxy, once it gets hot and you start pushing with the flathead the pieces will basically shatter off and they are hot to boot so yeah..watch out for burns.
Secondly: Do NOT try to crank the engine without a spark plug attached and grounded.  The SSI (if working) will build up current and end up shorting some internal component as it tried to find it's own ground.

Anyway after breaking the trace, and soldering both the jumper and the diode my SSI is now a pickup coil :)

I've gotten excellent spark with Ed's setup and it's MUCH cheaper than replacing the SSI with either new or even refurbished modules.

Tuesday, July 7, 2015

GT rebuild: Sears ST/16

I'm veering off my normal path here with a non-IT posting.  I've recently gotten into rebuilding garden tractors, and my latest project is a 1973 Sears ST/16. I bought it from a guy down towards the southern end of the state and it came without a mowing deck but with a front blade, rear blade, a single bottom moldboard plow and a disc.
These units were built tough before built tough was a trademark. It originally came with a Tecumseh OH160 16hp overhead valve, single cylinder engine. And a 3 forward and 1 rear speed geared transmission.


Here it is at the beginning. Rusty and ugly.

I have taken the hood, grill and fenders off and repainted them all. The white I used was IH white, the yellow was New Caterpillar yellow. This hog came with heavy wheel weights and a body weight that I sold the front blade which was for a John Deere 200 series.

Engine wise is smoked like a freight-train.. lots of blow by. So with the ring kits being upwards of $60 I found a replacement engine for $75 (which gives me a lot of spare engine parts) which ended up being an OH140 14hp Tecumseh.  Same exact setup only with a smaller piston.

Other existing issues included a leaky gas tank, frozen up carb, old fuel lines, no fuel filter or pump, the transmission fluid was horribly old, left front tire has holes and the muffler was rotten.

I post this now because I'm almost at the end of this rebuild.. I'll follow it up with an after pic once fully completed.

Monday, June 8, 2015

Powershell - Change computer object description to username

Two years ago, with help from ExpertsExchange, I had created a VisualBasic script to collect the currently logged on users username, and set the computers description to that username in AD.

To us it's purpose was to help associate the computers to the actual user, since computers change hands, get re purposed and you don't always remember to change the description.

So here's the old script:

On Error Resume Next
strComputer = "."

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2").ExecQuery("Select Description FROM Win32_OperatingSystem")
For Each object In objRegistry
strDescription = object.Description 
Next 


Set objSysInfo = CreateObject("ADSystemInfo")
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
objComputer.Description = strDescription
objComputer.SetInfo

And the new Powershell version:

Import-Module ActiveDirectory
$computer = $env:computername
$username = $env:USERNAME
set-adcomputer $computer -description $username


Shocking, no?  Another reason I :heart: Powershell.


UPDATE:

Well this script has failed me.  Well not the script mind you but I ran into an issue in it's utilization here that will not work.  Our images of Win7Ent do not contain the RSAT tools for obvious reasons.. but that means that my attempt to call this via a GPO logon script failed because running this script locally on a machine that does not have the module means import-module ActiveDirectory fails.

The fix for our scenario was to fall back to the visual basic script above.  It's still called from a GPO though, after giving Authenticated Users write permission to computer-Description.


Wednesday, June 3, 2015

Powershell - Script generates CSV with computer names and bitlocker recovery key and TPM-OwnerInformation

So here at work we're in the process of Bitlocking 'important' users laptops and to help keep track and poll AD I went looking for a powershell script to accomplish this.  I found a script here: https://gallery.technet.microsoft.com/ScriptCenter/4231a8a1-cc60-4e07-a098-2844353186ad/

Props to Jan Egil Ring, his relevant blog post is http://blog.powershell.no/2010/10/24/export-bitlocker-information-using-windows-powershell/ for creating the first iteration using  Quests Powershell addons back in 2010.

I don;t use the QAD tools anymore so I went to work on configuring the script to run natively.


So this script generates a CSV with all computer objects with Windows 7 or 8, pulls the msTPM-OwnerInformation and msFVE-RecoveryInformation and marks the columns for the recovery key and TPM owner as either True or False.

Anyway here's the meat:

# 
# 
# NAME: Get-BitlockerEnabledComputer.ps1 
# 


# EDITTED BY: Benjamin Hart
# EMAIL: Invalid.path@gmail.com
# 
# COMMENT: Script to retrieve BitLocker-information for all computer objects with Windows 7 or Windows Vista in the current domain. 
# 
#          The information will be exported to a CSV-file containing the following information: 
#          -Computername 
#          -OperatingSystem 
#          -HasBitlockerRecoveryKey 
#          -HasTPM-OwnerInformation 
#           
#          Required version: Windows PowerShell 1.0 or 2.0 
#          Requried privileges: Read-permission on msFVE-RecoveryInformation objects and Read-permissions on msTPM-OwnerInformation on computer-objects (e.g. Domain Admins) 
#     
#  
# 




import-module activedirectory 

#Custom variables
$CsvFilePath = "path_to_csv" 

set-location AD:
$bitlockerenabled = Get-ADObject -LDAPFilter '(objectclass=msFVE-recoveryInformation)' -Properties cn,distinguishedname | ForEach `
{
    ((($_ | Select -ExpandProperty DistinguishedName) -split ",?CN=")[2] -split ",")[0]
}

$computers = Get-ADComputer -filter * -Properties cn,OperatingSystem,msTPM-OwnerInformation | Where-Object {$_.operatingsystem -like "Windows 7*" -or $_.operatingsystem -like 
"Windows 8*"} | Sort-Object msTPM-OwnerInformation

#Create array to hold computer information 
$export = @() 

read-host "Created array"

foreach ($computer in $computers) 
  { 
    #Create custom object for each computer 
    $computerobj = New-Object -TypeName psobject 
    
     
    #Add name and operatingsystem to custom object 
    $computerobj | Add-Member -MemberType NoteProperty -Name DistinguishedName -Value $computer.Name 
    $computerobj | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $computer.operatingsystem 
     
    #Set HasBitlockerRecoveryKey to true or false, based on matching against the computer-collection with BitLocker recovery information 
    if ($computer.cn -match ('(' + [string]::Join(')|(', $bitlockerenabled) + ')')) { 
    $computerobj | Add-Member -MemberType NoteProperty -Name HasBitlockerRecoveryKey -Value $true 
    } 
    else 
    { 
    $computerobj | Add-Member -MemberType NoteProperty -Name HasBitlockerRecoveryKey -Value $false 
    } 
    
     
    #Set HasTPM-OwnerInformation to true or false, based on the msTPM-OwnerInformation on the computer object 
     if ($computer."msTPM-OwnerInformation") { 
    $computerobj | Add-Member -MemberType NoteProperty -Name HasTPM-OwnerInformation -Value $true 
    } 
    else 
    { 
    $computerobj | Add-Member -MemberType NoteProperty -Name HasTPM-OwnerInformation -Value $false 
    } 
   #  $computerobj | add-member -membertype noteproperty -name recoveryguid -value $object.recoveryguid
   #$computerobj | add-member -membertype noteproperty -name When-Created -value $computer.whencreated
#Add the computer object to the array with computer information 
$export += $computerobj 

  } 

#Export the array with computerinformation to the user-specified path 
$export | Export-Csv -Path $CsvFilePath -NoTypeInformation | sort hastpm-ownerinformation -descending
read-host "Exported csv"