Archive for July, 2010


I was asked to audit which printers were shared by a large group of Servers and here is a nice one liner I come up with that got me the information I needed:

First create an array with all your server host names e.g

$servers = 'SERVER01','SERVER02'

Then use the  Get-WmiObject cmdlet as follows:

gwmi Win32_Printer -computername $servers -namespace root\CIMV2 | select  __Server, DeviceID, DriverName

An example of the output:

__SERVER                                  DeviceID                                  DriverName

--------                                  --------                                  ----------

SERVER01                                  SRV1P254                                 hp color LaserJet 2550 PCL 6

SERVER01                                  SRV1P004                                 RICOH Aficio MP C5000 PCL 5c

SERVER01                                  SRV1P003                                 HP Color LaserJet 2600n

SERVER01                                  SRV1P002                                 HP Color LaserJet 4700 PCL 6

SERVER01                                  SRV1P001                                 HP LaserJet 4100 PCL 6

SERVER01                                  Microsoft XPS Document Writer            Microsoft XPS Document Writer

SERVER01                                  CutePDF Writer                           CutePDF Writer

SERVER02                                  Microsoft XPS Document Writer            Microsoft XPS Document Writer

SERVER02                                  SRVP254                                  hp color LaserJet 2550 PCL 6

Enjoy,

jfrmilner


I should start by pointing out that I’ll not be doing a PowerShell basics post as this has been done to death by the blogging community. If you don’t have much experience with PowerShell I suggest you google for this information or better still take a look at the excellent CBTnuggets PowerShell on-the-job training over at http://www.cbtnuggets.com/series?id=456 .

One of the things I love about PowerShell is the way that you can effortlessly interact with .NET and this example will do just that by hooking into the System.Web Assembly (in System.Web.dll). Further details about this class can be found at http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx

First you’ll need to load the System.Web assembly with this line:

[Reflection.Assembly]::LoadWithPartialName("System.Web")

Now you can create passwords with the following line:

[System.Web.Security.Membership]::GeneratePassword(10,2)

NOTE: The two numeric values in parentheses represent password length and the amount of non-alphanumeric characters used respectively.

You can use this to create a batch of 50 passwords:

1..50| % {[System.Web.Security.Membership]::GeneratePassword(10,2)}

Or maybe just one very large password!:

[String]::Join("",(1..50| % {[System.Web.Security.Membership]::GeneratePassword(100,2)}))

Enjoy,

jfrmilner