Export and import WLAN profiles

Network Shell (Netsh) is a command-line utility that makes it possible to work with various server roles and operating system components in Windows, and have been available since Windows 2000. Its commonly used to change network interface information such as IP-addresses, as well as for resetting the TCP/IP stack. For a complete overview of the capabilities of netsh, have a look at the Netsh Command Reference on Microsoft TechNet.

Starting with Windows Vista/Windows Server 2008, netsh provides commands for Wireless Local Area Networks (WLAN). This makes it possible to import and export WLAN profiles, which can be useful when re-installing your computer or maybe when deploying corporate computers where WPA Enterprise is not used.

In combination with Windows PowerShell its easy to import and export WLAN profiles using netsh. I`ve provided a script containing two PowerShell functions:

  • Export-WLAN
  • Import-WLAN

Click on the thumbnails to see help info for the functions:

image image

The script is available here.

Note that Windows Vista/7 has a concept of all-user and per-user WLAN profiles:

image

All-user profiles is the default, and the functions are not customized to work with per-user functions.

Introduction to PowerGadgets

 

PowerGadgets is an IT monitoring product from SoftwareFX, making it possible to create real-time monitoring gadgets such as charts, gauges and maps. Its been on the market for some years, I think it was released back in 2006 in the timeframe Windows PowerShell 1.0 was released.

When the product is installed you can either add it to an existing PowerShell session by using Add-PSSnapin PowerGadgets, or by launching it from the Start-menu where you can also find the help-file, a quick start guide as well as a PowerGadgets Creator:

image

 

To show some basic usage Ive decided to use Microsoft Exchange Server 2010 as a data source to provide a couple of gauges showing the number of e-mails sent and received the last day:

001
002
003
004
005
Add-PSSnapin PowerGadgets
Import-PSSession -Session (New-PSSession -ConnectionUri http://exch-jr-02.rbk.ad/PowerShell -ConfigurationName Microsoft.Exchange) -CommandName Get-MessageTrackingLog 

Get-MessageTrackingLog -Start (Get-Date -Format MM.dd.yyyy) -EventId receive | Measure-Object | Out-Gauge -Type digital -Refresh 00:00:05 -Caption “Received – last day”
Get-MessageTrackingLog -Start (Get-Date -Format MM.dd.yyyy) -EventId send | Measure-Object | Out-Gauge -Type digital -Refresh 00:00:05 -Caption “Sent – last day”

 

The sample code above will produce the following two gauges which refreshes every 5 seconds:

image

In the example above Ive installed PowerGadgets on my local workstation, and leverage PowerShell remoting to access the information from the Exchange server.

As far as I can see, there are examples provided only for the Out-Chart cmdlet within the PowerShell help text, a good idea would be to add examples to all of the PowerGadgets cmdlets in upcoming releases, as PowerShell are built for discovery through the help system.

Although there are many examples provided in the Samples-directory in the installation-folder:

image

In addition the help file are great for information and some examples:

image

 

A fast and easy way to customize the output without going deep into the documentation is to use the –Configure parameter on the Out-* cmdlets.

This will popup your data in the PowerGadgets Template Creator:

image

When changes are made, you can save the configuration as a template file, which can then be specified by using the –Template parameter on the cmdlets.

By using the –Output parameter, you can specify a filename (png,bmp or wmf)) which lets you i.e. display the output on a webserver. To automate the process, the scripts you create may be set up as scheduled tasks.

An example showing the number of users per Organization Unit using Out-Chart:

001
002
003
004
005
006
007
008
009
010
011
012
Add-PSSnapin PowerGadgets
Import-Module ActiveDirectory 

$OUs = Get-ADOrganizationalUnit -SearchBase “OU=Departments,DC=contoso,DC=com” -SearchScope OneLevel -Filter * |
Select-Object Name,DistinguishedName
$data = foreach ($OU in $OUs) {
$count = (Get-ADUser -Filter * -SearchBase $OU.DistinguishedName | Measure-Object).Count
add-member -inputobject $ou -membertype NoteProperty -Name Count -Value $count
Write-Output $ou
}

$data | Out-Chart -Values Count -Label Name

 

image

 

There is also an Out-Map cmdlet available, which PowerShell MVP Marco Shaw has provided some example usage on here.

 

Pricing

The pricing of the product is 99 USD, however, you may first want to download a 30 days trial from here.
If you`re an active PowerShell community member, you may also qualify for a free license through the PowerGadgets ISV program.

 

Resources

PowerGUI and PowerGadgets

Monitoring VMWare with PowerGadgets

Working with Active Directory Certificate Services from Windows PowerShell

In Active Directory Certificate Services, the primary administration interface is the MMC snap-in Certification Authority exposed through Server Manager in Windows Server 2008 and Windows Server 2008 R2:

image

More advanced administration options is available through the command line utility certutil.exe.

I recently worked with an environment with an unusual amount of issued certificates (several hundreds of thousands), and working with the MMC-tools was not efficient.

I first started by exporting the issued certificates to a CSV-file by using certutil.exes csv option. This options seems to be new in Windows Server 2008 R2, although I havent found any documentation on this. Actually it`s possible to use certutil.exe from a Windows Server 2008 R2 member server against a Certification Authority running an earlier version of Windows Server to export issued certificates to CSV. It should also be noted that this can be accomplished using the Export List option in the Certification Authority MMC in both Windows Server 2008 R2 and earlier versions of Windows Server.

When the CSV-file are exported, we can import it to Windows PowerShell and do things like grouping and sorting:

001
002
003
004
005
006
007
008
009
010
011
#Export certificates to CSV
certutil -view -out "RequestID,RequesterName,RequestType,NotAfter,CommonName,Certificate Template" csv > c:tempcerts.csv

#Import CSV
$csv = Import-Csv C:Tempcerts.csv

#Group by requester name, and sort by count
$csv | Select-Object "requester name" | Group-Object -Property "requester name" | Sort-Object -Property count

#Work further with a specific computer based on the above results
$computer = $csv | Where-Object {$_."requester name" -eq "computer01"}

 

Note that using CSV when working with very large data sets might consume large amounts of system resources (up to 2,5 GB in my case), so this might not be the best approach. Another option would be to work directly against the Certification Authority database, where we can set filters directly on the queries.

There are several Com-objects available for working with Active Directory Certificate Services, which makes it possible to work directly against the Certification Authority database from PowerShell.

PowerShell MVP Vadim Podans has written a blog-post showing how this can be accomplished.

Another Com-object to look into is the ICertAdmin2 Interface, which can be accessed from PowerShell like this:

001
002
003
004
005
006
007
008
009
010
011
012 013
014
#Create Com-object
$certadmin = new-object -com "CertificateAuthority.Admin.1"

#Explore Com-object
$certadmin | Get-Member

#Sample usage for one of the available methods
$certadmin.DeleteRow(
"lab-dc-01Issuing CA 01", #Config-string
 0x0, #Flags, not set
 0x0, #Date, not set when using RowID
 0x0, #Table, set to 3 for CVRC_TABLE_REQCERT
 21 #RowId
 )

Microsoft MVP Award

 

The Microsoft Most Valuable Professional (MVP) is an award presented by Microsoft for the employees or individuals or consultants working outside Microsoft. Microsoft considers MVPs to be technical community leaders from around the world who have been awarded for voluntarily providing technical expertise towards technical communities supporting Microsoft products or technologies. An MVP is awarded for contributions over the past year. (Quote from Wikipedia)

 

Today I received this e-mail from Microsoft:

Dear Jan Egil Ring,
Congratulations! We are pleased to present you with the 2011 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in PowerShell technical communities during the past year.

I feel very honored to be a part of this amazing community, and look forward to interact with fellow peers in the PowerShell MVP community.

 

Resources

About the MVP Award Program

Windows PowerShell MVP Awardees

MVPs.org community site

Microsoft MVP FAQ