February
01
Posted on 01-02-2016
Filed Under (powercli, powershell) by admin

This is a quick one-liner to list the serial number of all your ESXi hosts. Enjoy!

Get-VMHost | Get-View | Select Name, @{l=”SerialNumber”; e={$_.Hardware.SystemInfo.OtherIdentifyingInfo.IdentifierValue.split(“,”)[0]}}

(0) Comments    Read More   
June
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   
October
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   
June
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   
October
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