Basic Usage

Prerequisites

Install the Module

You must install the provider module before you will be able to use it. For information on installing the provider, see Installation.

Collect Membership Provider Configuration

At present, the PowerShell provider is capable of using SQL Server-backed Membership stores, You will need the configuration of the Membership provider. Specifically, you will need the following configured properties of the Membership provider:
  • ConnectionString
  • EnablePasswordReset
  • EnablePasswordRetrieval
  • RequiresQuestionAndAnswer
  • RequiresUniqueEmail
  • MaxInvalidPasswordAttempts
  • MinRequiredNonalphanumericCharacters
  • MinRequiredPasswordLength
  • PasswordAttemptWindow
  • PasswordStrengthRegularExpression
  • ApplicationName
  • PasswordFormat

Typically these parameters of the Membership provider are specified in the website's web.config file:
	<connectionStrings>
		<add name="ApplicationServices" connectionString="Data Source=MySQLServer;Initial Catalog=aspnetdb;Persist Security Info=True;User ID=aspnet;Password=Secret1234" providerName="System.Data.SqlClient"/>
	</connectionStrings>

         ...
	<membership>
		<providers>
			<clear/>
			<add name="AspNetSqlMembershipProvider" 
                          type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
                          connectionStringName="ApplicationServices" 
                          enablePasswordRetrieval="false" 
                          enablePasswordReset="true" 
                          requiresQuestionAndAnswer="false" 
                          requiresUniqueEmail="false" 
                          passwordFormat="Hashed" 
                          maxInvalidPasswordAttempts="5" 
                          minRequiredPasswordLength="6" 
                          minRequiredNonalphanumericCharacters="0" 
                          passwordAttemptWindow="10" 
                          passwordStrengthRegularExpression="" 
                          applicationName="/" />
		</providers>
	</membership>

Importing the Provider into your PowerShell Session

Once the Membership PowerShell Provider is installed, you can pull it into any PowerShell session using the following command:
PS> import-module Membership


You can verify that the module was loaded properly using the get-psprovider cmdlet:
PS> get-psprovider Membership

Name                 Capabilities                                      Drives
----                 ------------                                      ------
Membership           Filter, ShouldProcess                             {}

Defining your Membership Drive

All access to the membership store is done through a drive. To define the drive, use the following command, replacing the (placeholder) values with the values used for your specific membership store (note that spacing and end-of-lines were added for readability):
PS> new-psdrive -psprovider Membership -root '' -name users -connectionString (string) 
   -enablePasswordReset ($true|$false) -enablePasswordRetrieval ($true|$false) 
   -requiresQuestionAndAnswer ($true|$false) -requiresUniqueEmail ($true|$false) 
   -maxInvalidPasswordAttempts (number) -minRequiredNonalphanumericCharacters (number) 
   -minRequiredPasswordLength (number) -passwordAttemptWindow (number) 
   -passwordStrengthRegularExpression (string) -applicationName (string) 
   -passwordFormat (clear|encrypted|hashed)

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
users                                  Membership

Note that the only required parameters to the new-psdrive cmdlet are the -psprovider, -root, -name, and -connectionString parameters. If unspecified, the remaining parameters default to the same default values used when a new ASP.NET web site is created with Membership support; specifically:
  • enablePasswordRetrieval="false"
  • enablePasswordReset="true"
  • requiresQuestionAndAnswer="false"
  • requiresUniqueEmail="false"
  • passwordFormat="Hashed"
  • maxInvalidPasswordAttempts="5"
  • minRequiredPasswordLength="6"
  • minRequiredNonalphanumericCharacters="0"
  • passwordAttemptWindow="10"
  • passwordStrengthRegularExpression=""
  • applicationName="/"

You can validate that the drive was created using the get-psdrive cmdlet:
PS> get-psdrive users

Name           Used (GB)     Free (GB) Provider      Root                                               CurrentLocation
----           ---------     --------- --------      ----                                               ---------------
users                                  Membership

Supported Operations

Once the drive is installed in your current session, you can use the standard PowerShell item cmdlets to spelunker and modify your Membership store from the console. The following item cmdlets are supported by the Membership PowerShell Provider:
  • test-path: verifies if a Membership User exists
  • new-item: creates a new Membership User
  • get-item: retrieves an existing Membership User
  • set-item: updates an existing Membership User
  • remove-item: deletes a Membership User
  • get-childitems: enumerates Membership Users in the store

Supported Path Syntax

The Membership PowerShell Provider understands several forms of path syntax supported by PowerShell. Each path keys on the username of the Membership User object to locate it. In the examples below, the drive name is "users" and the username value is "beefarino".
Path Format Template Example
drive-qualified <drive>:/<username> users:/beefarino
provider-qualified membership::<username> membership::beefarino

For More Information

For more usage information, and for details about using specific item cmdlets against the provider, please see Advanced Usage.

Last edited Jul 26, 2010 at 10:46 PM by beefarino, version 3

Comments

No comments yet.