Oct
17
Posted on 17-10-2014
Filed Under (Uncategorized) by admin

Remember that application update you were doing at 2AM three months ago? You know, the one where step 1 in your change document was to take a VMWare snapshot of the VM you were about to make changes to? Of course you do, because you’re a good admin like that. We’ve all been there, you take a snapshot of a VM and after a successful change you jump right to the “Miller time” step, completely disregarding the “remove snapshot step”. Well instead of being reminded that you left that snapshot hanging out there with a full datastore, you should schedule this report to run daily or weekly and save yourself the headache. You’re welcome.

 

#===========================
# Created on:   10/16/2014
# Created by:   Dan Wagoner
# Organization: NBN
# Filename:     Get-SnapShotReport.ps1
# Description:    This script generates an HTML report of outstanding
#                VMWare snapshots, and correlates them to a user via
#                VMWare events.
#
# Usage: Get-SnapShotReport.ps1 -Server <vCenter/ESXi Server Name>
#==========================

Param(
[Parameter(Mandatory=$True)]
[string]$Server
)

Add-PSSnapin VMware.VimAutomation.Core
Connect-ViServer $Server

$email_to = “email@domain.com”
$email_from = “email@domain.com”
$email_server = “server.domain.com”
$email_subject = “VMWare Snapshot Report”
$snaps = @()
$currsnaps = Get-VM | ?{$_.PowerState -eq “PoweredOn”} | Get-Snapshot | Select VM, Name, Created, SizeGB
$css = “<style>BODY{font-family: Arial; font-size: 10pt;}
TABLE{border: 1px solid black; border-collapse: collapse;}
TH{border: 1px solid black; background: #dddddd; padding: 5px;}
TD{border: 1px solid black; padding: 5px;}</style>

foreach ($snap in $currsnaps){
$user = ($snap.VM | Get-ViEvent | ?{$_.CreatedTime -match $snap.Created} | ?{$_.FullFormattedMessage -match “snapshot”}).Username
$builder = New-Object System.Object
$builder | Add-Member -Type NoteProperty -Name VM -Value $snap.VM
$builder | Add-Member -Type NoteProperty -Name SnapName -Value $snap.Name
$builder | Add-Member -Type NoteProperty -Name TimeStamp -Value $snap.Created
$builder | Add-Member -Type NoteProperty -Name SizeGB -Value $([math]::floor($snap.SizeGB))
$builder | Add-Member -Type NoteProperty -Name CreatedBy -Value $user
$snaps += $builder
}

if($snaps){
Send-MailMessage -To $email_to -From $email_from -SmtpServer $email_server -Subject $email_subject -BodyAsHtml ($snaps | ConvertTo-Html -Head $css | Out-String)
}

(0) Comments    Read More   
Sep
10
Posted on 10-09-2014
Filed Under (Uncategorized) by admin

Windows Server 2012 brings PowerShell capabilities to tons of Windows services. This quick little script makes use of some of these new capabilities as they apply to Windows DHCP services. I wanted to create a script that monitors DHCP scope utilization to ensure I have plenty of free leases available in all of my scopes – so that’s exactly what this script does. Use task scheduler to run the script at some interval and rest assured your clients will always get an IP address right when they need it most. Enjoy!

 

$threshold = 90
$email_to = “<name@domain.com>”
$email_from = “<name@domain.com>”
$email_server = “<smtp server name>”
$scopes = Get-DhcpServerv4ScopeStatistics

foreach ($scope in $scopes) {
if($scope.PercentageInUse -gt $threshold){
$email_body = “Scope: $($scope.ScopeId) – pool IPs in use is $([math]::round($scope.PercentageInUse, 0))%”
Send-MailMessage -To $email_to -From $email_from -SmtpServer $email_server -Subject “scope threshold exceeded – $($scope.ScopeId)” -Body $email_body
}
}

(0) Comments    Read More   
Oct
26
Posted on 26-10-2013
Filed Under (Uncategorized) by admin

A few weeks ago we had some power fluctuations that resulted in the power flickering on and off a handful of times before going out completely. Every time this happens, I hold my breath right after the power comes back on and hope that none of my beloved electronics are fried; but this time, I wasn’t so lucky. My Asus RT-N16 router was toast.

Symptoms: When I plugged the power adapter into the router, the power light came on for a few seconds. Shortly afterwards I would hear a slight “click” and the device would just power down.

This definitely sounded like a power issue, so I wasn’t hopeful. But knowing that my warranty had long expired, I was definitely going to peel it open and check out the situation. Before I got the screw drivers and soldering iron out, I plugged in the wall wart and did a quick voltage test to ensure that wasn’t the culprit. 12.56V output from this 12V 1.25A power adapter was definitely within spec.

The RT-N16 case is a simple assembly; remove the 4 sticky rubber feet to uncover 4 philips-head screws. After removing the screws, the top pops right off with ease. Upon inspecting the circuitry, I immediately noticed a 680uF capacitor that had crowned a bit. I de-soldered this  capacitor and scrounged around until I found a 480uF capacitor (close enough). I know it’s a major pain to solder through-hole components into vias that have already been used, so I just soldered a couple of wires to the bottom of the board and soldered my new capacitor to the other end of the wires. A bit of masking tape for mounting (couldn’t find my hot glue gun), and we were back in business.

Hopefully this will encourage a few people out there to break the warranty seal and poke around for themselves. I’m sure there are tons devices out there that have been thrown away and replaced when the fix was a $0.5 capacitor and 15 minutes of time.

Bad capacitor in Asus RT-N16 Bad capacitor in Asus RT-N16 Asus RT-N16 capacitor replaced

 

(26) Comments    Read More   
Jun
07
Posted on 07-06-2013
Filed Under (powershell) by admin

printerI recently had a request to audit printer usage on specific printers in the organization. All of our network-enabled printers are shared from a single Windows 2003 Server, so my first thought was parsing event logs. The result is the attached Powershell script. Just feed the script a start and end date to filter by and it will parse the event log entries into Powershell properties that can be filtered, exported or mangled in any way you see fit. I’ve also added a department look up using the Quest AD tools since that was one of the key pieces of information we were interested in gathering. Feel free to make use of the script and modify the output however it suits your needs.

 

Download Get-PrinterEvents.ps1

(0) Comments    Read More   
Oct
09
Posted on 09-10-2012
Filed Under (powershell) by Dan

A quick and dirty script for listing all distribution groups that a mailbox user is a member of. Seems easy enough, but I couldn’t find anything on the googlez…so here ya go!

$user = Read-Host “Please enter the name of a user”

if (Get-Mailbox $user){
$dgs = Get-DistributionGroup -ResultSize unlimited

write-host
write-host “$user is a member of the following distribution groups (this may take a few minutes):”
write-host

$dgs | foreach {if ((Get-DistributionGroupMember $_.Name) -match $user){write-host $_.Name}}
}
else{
Write-Host “User not found…run script again. Sober up first.” -foregroundcolor red
Write-Host

}

(0) Comments    Read More   
Jun
15
Posted on 15-06-2012
Filed Under (powershell) by Dan

PowerCLI

Just a quick script that lists all Windows VMs on a VMWare host and returns the version of Windows that is running. It goes without saying that you must have Administrative privileges on the machines being queried (this could be changed with a slight tweak to the Get-WMIObject command). Without further ado:

$output_file = “path_to_file”
$vms = Get-VM | ?{$_.PowerState -eq “PoweredOn”}
$vmos = foreach($vm in $vms) {Get-WmiObject -ComputerName $vm.Name Win32_OperatingSystem -EA SilentlyContinue | Select-Object @{Name=”ComputerName”; Expression={$vm.Name}}, @{Name=”OSVersion”; Expression={$a = $_.Name.split(“|”); $a[0]}}}
$vmos | Export-Csv $output_file -NoTypeInformation

write-host “Process complete. Output saved to $output_file” -foregroundcolor “yellow”

(1) Comment    Read More   
Nov
22
Posted on 22-11-2011
Filed Under (Arduino, electronics) by Dan

I tried compiling Hangmanduino (see original post here) again using v 0021 of the Arduino IDE and found out quickly that things had changed. So I began troubleshooting and found that the WString library I was using was obsolete in the new IDE. Long story short, I was able to make a few adjustments to the code and got it up and running. Get the new code here (no need to download any additional libraries).

Enjoy!

(0) Comments    Read More   
Oct
07
Posted on 07-10-2011
Filed Under (powershell) by Dan

So I haven’t been completely truthful with everyone up until this point. The truth is, my day job consist of a lot of corporate-like tasks since I’m a Systems Administrator. One of my many responsibilities is administration of an Exchange 2010 environment. I’m constantly being thrown curve balls and tasks that cause me to think outside of the Microsoft box. I’ve decided to branch out and share some of the problems and (more importantly) solutions that I’ve come up with. Hopefully these will help someone out there.

This is a problem we’ve been dealing with since day 1 with our Exchange environment. We have separate partitions dedicated to each database’s logs. Once and a while a client or end device burps and causes the logs to grow out of control and cause major problems for the database. We have a monitoring solution, however, that is even prone to issues once and while. The cure was a 2nd layer of protection in the form of the following powershell script. This script runs every 5 mins and reports the percent of free space remaining of each of the log partitions (luckily we named the partitions appropriately so filtering VolumeName for “LOG” was a quick fix). If the free space remaining is less than the configured threshold (20% in my case), an email/page is sent. Nothing too fancy, but definitely a handy little life saver. And without further ado – the code:

$mbxs = “[mailboxserver1]“, “[mailboxserver2]“, “[mailboxserver3]”
$maxthreshold = 20  # disk remaining percentage threshold.
$email_to = “[email_to_address]”  # where you want the alert email sent
$email_from = “[email_from_address]”  # where you want the alert email to come from
$email_smtp_server = “[your_smtp_server]”  # smtp server used to send alert email
$email_subject = “EXCHANGE LOG LUN SPACE ISSUE!”  # subject of the alert email
$email_body = “”

for ($i = 0; $i -lt $mbxs.Length; $i++){
Get-WMIObject Win32_LogicalDisk -Computer $mbxs[$i] | where {$_.VolumeName -match “LOG”} | foreach{
$server = $mbxs[$i];
$volname = $_.VolumeName;
$freegbs = [math]::round($_.FreeSpace / 1GB, 0);
$sizegbs = [math]::round($_.Size/ 1GB, 0);
$percentfree = [math]::round(($freegbs / $sizegbs) * 100, 0);

if ($percentfree -le $maxthreshold){
$email_body = “Server: ” + $mbxs[$i] + “`r Volume Name: ” + $volname + “`r Disk Size: ” + $sizegbs + “GB `r Space Remaining: ” + $freegbs + “GB `r Percent Remaining: ” + $percentfree + “%”
Send-MailMessage -To $email_to -SmtpServer $email_smtp_server -Subject $email_subject -From $email_from -Body $email_body
}
}
}

(0) Comments    Read More   
Oct
05
Posted on 05-10-2011
Filed Under (Arduino, electronics) by Dan

I just spent the last 3 days (on and off) troubleshooting why my Arduino IDE wouldn’t open properly on my Windows 7 64-bit machine. I thought I’d share the fix with the rest of the world as my Google searches returned nothing in the way of useful answers to my issue. For my issue, I’d click on arduino.exe and the splash screen would display, shortly afterwards, it would disappear along with the arduino.exe process that was running in the background. I had tried debugging the java launcher, that looked fine. I had checked permissions on the folder, flipped the compatability mode of the exe, you name it. In the end I needed to check the “disable visual themes” checkbox on the exe (see screenshot).

Full path to change this checkbox: C:path_to_arduinoarduino.exe > right-click >compatibility tab > check “disable visual themes”  (not a bad idea to check “Run as Administrator” while you’re in here) > OK

Hopefully this helps someone else out there as they desperately scour the interwebs for a solution to get back into the IDE.

arduino_exe_screen

(1) Comment    Read More   
Sep
01
Posted on 01-09-2010
Filed Under (Arduino, Asterisk, electronics) by Dan

A recent comment by the009 got me thinking…I’ve been able to get Asterisk grab info about sensors connected to an ethernet-enabled Arduino, but how about the other way around? What if you could allow your Arduino to make outbound calls through your Asterisk system to make a make-shift alarm system, or over-powered doorbell? Well, wait no longer! Here’s how it works:

Asterisk: A php script lives on your Asterisk server (hosted up by apache) that, when it’s accessed, checks to make sure the client accessing it matches a pre-defined IP of your Arduino. If so, it creates a call file with the criteria that you configure to call a number of your choice and drops it in the Asterisk outgoing queue directory, triggering Asterisk to make a call. (I would highly suggest you only set this up on a server that doesn’t have port 80 open to the world!)

Arduino: The sketch code is easy…simply trigger a client connection to the Asterisk server when a button is pushed, motion sensor tripped, or ultra sonic range finder measures a particular distance (that part is up to you). As long as the Arduino’s IP matches the allowed IP configured in the php script, your phone should ring!

Make it happen:

  1. To get started, download the code and extract the files.
  2. scp arduino_call.php into your web directory on your asterisk server.
  3. Next, add the lines from extensions_custom.conf (zip package) to /etc/asterisk/extensions_custom.conf
  4. Edit the variables at the top of arduino_call.php to match your configuration.
  5. Upload the sketch to your arduino, customizing to your configuration (of course!).
  6. Adapt it to your project!

Feel free to edit and manipulate this script to fit your needs, I just ask that you add a comment to this page explaining how you used it. Videos / pictures are always welcomed as well!

(4) Comments    Read More