Wednesday, August 20, 2008

Print Queue Analysis

Wes - Can you tell us what printers on a particular print server have more then 10 jobs? Why yes, I can. And here is how you can do it.

$Printers = Get-WmiObject `
-Class Win32_PerfFormattedData_Spooler_PrintQueue `
-ComputerName 'hisprint-p01'`
-Filter 'Name <> "_Total"'
foreach ($Printer in $Printers) {
if($Printer.Jobs -ge 10){
Write-Host $Printer.Name $Printer.Jobs
}
}


Results:
RHS780 75
OSUHE235 15
MMCT475B 32
DNW375 74

Admittedly, this is could be much more generic. Also, a nice visual representation could be made via PowerGadgets. These are left to the reader as an exercise....

Friday, August 8, 2008

Getting Available Memory On Remote Servers

I am often asked to give total and available memory across our enterprise to our Disaster Recovery guys. Here is a simple script that achieves that goal:

$Servers = Get-Content 'c:\ProductionScripts\Servers.txt'
Write
-Host "Server,Total,Free"
foreach ( $server in $Servers )
{
$drives
= Get-WmiObject `
-Class Win32_LogicalDisk `
-ComputerName $server `
-Filter "DriveType=3" `
-ErrorAction SilentlyContinue
$size
= 0
$available
= 0
foreach($drive in $drives)
{
[
double]$size += $drive.size
[
double]$available += $drive.freespace
}

$str
= "{0},{1},{2}" -f $server,[MATH]::Round($size/1MB),[MATH]::Round($available/1MB)
Write
-Host $str
}




Wednesday, August 6, 2008

External (outbound/inbound) eMail Verification

Given that MOM can only verify internal email, I was asked if there was a way to verify delivery of external bound email and receipt of external email. Following is a high-level description of a low-tech solution (using 2 scheduled PowerShell scripts).

  1. Scheduled PowerShell script that runs every 15 minutes that sends a specifically formatted email to gMail and GMX (a great Webmail!). The PowerShell script uses Send-SMTP from PSCX.
    Send-SmtpMail `
    -SmtpHost '###.osumc.edu' `
    -To '####@gmail.com' `
    -From '####@osumc.edu' `
    -Subject 'Cryptic text here' `
    -AttachmentPath 'D:\File.txt'

  2. gMail and GMX have advanced filtering capabilities. In this case, both look for the specifically formatted email. Once received, it sends back to our domain and is deleted.

  3. Email traverses through spam filter and then to final destination.

  4. Using custom Outlook rule/script, we look for the above email. When received, it places the email attachment into a file share and deletes the email. This is the weakest step in that it assumes 24/7 on an email client. I will be looking into a better way to do this step.

  5. The second PowerShell script looks for the LastWriteTime of the file that was stripped from the email and placed into the fileshare. If the interval is greater then 15 minutes, an event log entry is made.

    $c = New-TimeSpan ((Get-Item c:\ProductionScripts\eMailVerification\InBoundAttachment.txt).LastWriteTime) $(Get-Date)
    [
    int]$d = $c.TotalMinutes
    if ($d -gt 10)
    {
    $log
    = New-Object -Type System.Diagnostics.EventLog -ArgumentList Application
    $log.Source
    = "eMailVerification"
    $log.WriteEntry(
    "External eMail is taking $d minutes")
    }


  6. MOM then picks up the event and responds accordingly.

There are many different ways we can take this. I am considering parsing the email headers to grab the time-stamps. With these, I can potentially use PowerGadgets to create some dashboards.

Monday, July 21, 2008

A generic error occurred in GDI+.

OK - sometimes I am a little slow.
One of the reasons I decided to maintain a blog was to help myself remember those peculiar idiosyncrasies when scripting. Well shame on me....

My script was working fine until I added the most important piece (from a customer perspective) - the pretty chart. I am a big fan of PowerGadgets and try to utilize them wherever possible. Well, when I added Out-Chart with an output parameter, I received the ambiguous error, "A generic error occurred in GDI+".

So naturally, I pulled up Google and started searching. I vaguely recalled seeing this before but couldn't quite put my finger on it. Then I saw it. ....Permissions....

Yes! Now I remember. If the UNC path I am trying to save my chart to is wrong or permissions are not configure properly, I get the error.

Lesson Learned:

  1. Verify your UNC path before throwing it into your script.
  2. Use your blog!

Monday, July 14, 2008

Resolved! Conflict between PrimalScript and PSCX

On a couple workstations we noticed a conflict between PrimalScript Enterprise and the Powershell Community Extensions (PSCX). PrimalScript would throw an error and terminate when opening a file with a .ps1 extension.

PrimalScriptError2

I posted a follow-up on the Codeplex discussion board. Oisin quickly responded with a fix.

Hey guys,
Look for the line in your Pscx installed $profile that says:
Start-TabExpansion and comment it out with a #. This will workaround the problem.
- Oisin

Bingo! Now I can continue using PSCX (if you are not, you need to take a look) with PrimalScript. Thanks Oisin!

Thursday, July 3, 2008

Unable to use SourceSafe LAN service, performance of SourceSafe operations will not be optimal

When trying to utilize Microsoft Visual SourceSafe 2005 (VSS) with Sapian's PrimalScript Enterprise, I was getting the following warning, "Unable to use SourceSafe LAN service, performance of SourceSafe operations will not be optimal". Well we can't have that! To remedy this, you need to enable the LAN service on the VSS server.
  1. On your VSS server - Go to Microsoft Visual SourceSafe Administration
  2. Click on the Server menu item
  3. Click configure
  4. In the Server Configuration dialog box, select LAN
  5. Check the Enable LAN service for this computer.

Saturday, June 28, 2008

Previous Post mentioned in PowerScripting Podcast - Episode 30

The fine folks that bring us the PowerScripting Podcast (a must listen!), have included a previous post (DNS/WINS IP changes) in their 30th episode. I am honored!