PowerShell: Cancel all print jobs

Here’s a quick PowerShell script I put together to delete all print jobs from our Windows Server 2008 R2 print server. It’s run overnight as a scheduled task. We do this because sometimes our print accounting software doesn’t clear out old jobs if users haven’t released them at the printer.

$printers = Get-WmiObject Win32_Printer

if ($printers.Count -eq 0) {
    Write-Host -ForegroundColor red "No Printers Found"
    exit
}

foreach ($printer in $printers) {

    if ($printer.Local -and $printer.Shared)
    {
        Write-Host -ForegroundColor Green "Cancelling all jobs on: $($printer.Name)"
        $printer.CancelAllJobs()

    }
}

It will only clear print jobs on local printers that are shared out. There’s some more info about the Win32_Printer class and the CancelAllJobs method on MSDN.

Note that I haven’t included any error-checking in this script at all, so run it manually first to see if it will work. As always, run at your own risk.

To schedule it, simply create a new scheduled task:

    1. Run with highest privileges
    2. Run whether user is logged on or not
    3. Do not store password
    4. Action: Start a program: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    5. Arguments: -File “C:\path-to-script-file\name-of-script-file.ps1″

clearqueues-generaltab

clearqueues-action

Posted in PowerShell, Scripting, SysAdmin | Tagged , | 2 Comments

7-Zip tip – Quickly extract into a particular folder

If you need to extract a file into a particular folder, what do you normally do? Some people may copy the Zip file into the destination folder, and then unzip it. Others may launch their unzip tool of choice’s file manager and use the unzip wizard to point to the destination folder.

7-Zip provides a handy way to do this. All you need to do is right-mouse-drag the Zip file to the destination folder, release the right-mouse button, and go to 7-Zip –> Extract … from within the context menu.

20-10-2011 101712

20-10-2011 101905

I’d been using 7-Zip for years before I figured this one out.

Posted in Applications | Tagged | Leave a comment

Tools of the trade, AKA tools I couldn’t do without: 7-Zip

Another tool that I install straight away on new PCs is 7-Zip. I’m still amazed to see IT pros using unregistered (or dodgy) versions of WinRAR and WinZIP. 7-ZIP is better, faster, and free (open-source).

It can handle lots of formats, including ISO files, which I sometimes find handy.

7-Zip’s main features, as per their website. I’ve highlighted some of the formats that I regularly use 7-Zip with:

  • High compression ratio in 7z format with LZMA and LZMA2 compression
  • Supported formats:
    • Packing / unpacking: 7z, XZ, BZIP2, GZIP, TAR, ZIP and WIM
    • Unpacking only: ARJ, CAB, CHM, CPIO, CramFS, DEB, DMG, FAT, HFS, ISO, LZH, LZMA, MBR, MSI, NSIS, NTFS, RAR, RPM, SquashFS, UDF, VHD, WIM, XAR and Z.
  • For ZIP and GZIP formats, 7-Zip provides a compression ratio that is 2-10 % better than the ratio provided by PKZip and WinZip
  • Strong AES-256 encryption in 7z and ZIP formats
  • Self-extracting capability for 7z format
  • Integration with Windows Shell
  • Powerful File Manager
  • Powerful command line version
  • Plugin for FAR Manager
  • Localizations for 79 languages

Where: http://www.7-zip.org/
License: GNU LGPL – http://www.7-zip.org/license.txt

Posted in Tools of the trade | 1 Comment

Server 2008 R2: Online license edition upgrade

I’ve had to google this a few times, so I’ll blog the results here for future reference.

It’s possible to upgrade, for example, a Server 2008 R2 Standard server to Enterprise without rebuilding Windows. This is all covered in detail on the MS TechNet blogs.

The command to do so is:

DISM /online /Set-Edition:<edition ID> /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

To view what “editions” are available to upgrade to, do this:

DISM /online /Get-TargetEditions

I had issues using a valid VLSC key in this process. A comment by Brendan P of Microsoft explains why this is the case:

MAK keys map to multiple editions, so the underlying infrastructure doesn’t accept them. If you use the generic KMS client key, as Matthew suggests, that will allow you to proceed with the upgrade, and then you can either replace the key with a valid MAK post-upgrade or just use the KMS client key to activate against your internal KMS server.

The full list of KMS client keys can be found here on TechNet: technet.microsoft.com/…/ff793406.aspx

The command I ended up running to upgrade Server 2008 /w SP1 Standard (VL) to Enterprise was:

DISM /online /Set-Edition:ServerEnterprise /ProductKey:489J6-VHDMP-X63PK-3K798-CPX3Y

The successful run looks like this:

Deployment Image Servicing and Management toolVersion: 6.1.7600.16385
Image Version: 6.1.7600.16385
Starting to update components...Starting to install product key...Finished installing product key.
Removing package Microsoft-Windows-ServerStandardEdition~blah
[==========================100.0%==========================]
Finished updating components.
Starting to apply edition-specific settings...Restart Windows to complete this operation.Do you want to restart the computer now (Y/N)?
Posted in SysAdmin, Windows | Leave a comment

2TB SATA disks in a HP MSA20

msa20We recently needed to expand the storage space we use for backups. For this, we use a HP NAS 2000S, which is just a DL380 G3 with a faceplate, and two MSA20 storage shelves with SATA disks.

We had 12x 250GB, and 12x 750GB drives.

There is plenty of discussion around on the web about upgrading the drives yourself, and it’s hard to get a clear picture on whether or not 2TB drives are supported. On his blog, Stephen Wagner mentions that he had used a 2TB drive successfully. This was enough for us to know, so we went out and ordered 12x 2TB Seagate Constellation ES, and 12x 1TB of the same model. We chose to use these drives because that’s what our original HP-branded ones were.

There’s also another interesting blog article about upgrading the drives here which goes into some more detail.

Ours are now all up and running perfectly without any issues, we’re still running enterprise-class drives, and we saved a heap of money.

Posted in SysAdmin | 3 Comments