Microsoft NPS Archive/Restore Script

The following scripts can be used to backup or synchronize NPS/IAS/RADIUS servers:

nps-export.cmd
@ECHO OFF
FOR /F "tokens=2,3,4 delims=/ " %%a IN ('DATE /t') DO SET mydate=_%%a_%%b_%%c
copy /y %0\..\nps-config.xml %0\..\nps-config-%mydate%.xml
netsh nps export filename=%0\..\nps-config.xml exportPSK=YES

nps-restore.cmd
netsh nps import filename=%0\..\nps-config.xml

The export script will keep a daily copy of the NPS configuration for archive purposes.

Comments Off on Microsoft NPS Archive/Restore Script more...

Quota Notify Script

Here’s a small Perl script that can be modified to notify users on Windows file servers when they approach their quota limit. This is built into the new quota features in Windows Server 2003 R2 and beyond but the below can provide a bit more flexibility if needed. This also works on the “classic quota” features which we still have enabled.

#!/usr/bin/perl
$quotanotifypct = 80; # Notify users when they reach what percentage of their quota

%volumes = (
	e => "Faculty / Staff Y: drive",
	f => "Faculty / Staff W: drive",
	d => "Student Y: drive"
);

foreach $volume (keys(%volumes)) {
	@quotareport = `fsutil quota query $volume:`;

	foreach $line (@quotareport) {
		chomp($line);

		if($line =~ /SID Name.*User/gi) {
			$username = $line;
			$username =~ s/^.*\\//;
			$username =~ s/\s.*//;
			$quotaused = "";
			$quotathreshold = "";
			$quotapct = "";		
		} elsif($line =~ /Quota Used/gi) {
			$quotaused = $line;
			$quotaused =~ s/^.*=.//;
			$quotathreshold = "";
		} elsif($line =~ /Quota Threshold/gi) {
			$quotathreshold = $line;
			$quotathreshold =~ s/^.*=.//;
		}

		if (length($username) > 3 && $quotaused > 0 && $quotathreshold > 0 && $userNotified{$username} != 1) {
			$userNotified{$username} = 1;
			$quotapct = int( ($quotaused / $quotathreshold) * 100);

			if ($quotapct > $quotanotifypct) {
				print "NOTIFYUSER - $username - $quotapct - $volumes{$volume} - $quotaused - $quotathreshold\n";
			}
		}
	}
}
Comments Off on Quota Notify Script more...

Copyright © 1996-2010 Walt Howd. All rights reserved.
Jarrah theme by Templates Next | Powered by WordPress