Examples

The following examples demonstrate some of the ways you can use the Membership PowerShell Provider.

Getting a Custom Report of Users

PS> dir users: | format-table username,isapproved, lastlogindate

UserName                                                             IsApproved LastLoginDate
--------                                                             ---------- -------------
user00000001                                                              False 7/23/2010 9:19:36 PM
user00000002                                                               True 7/23/2010 8:40:13 PM
user00000003                                                              False 7/24/2010 8:56:38 PM
user00000004                                                               True 7/24/2010 8:49:25 PM
user00000005                                                              False 7/24/2010 9:17:37 PM

Resetting a User's Password

PS> $newpwd = ( get-item users:/user00000001 ).ResetPassword()

Filtering Users to those Logged In over the Past 24 Hours

PS> dir users: | where { $_.LastLoginDate -gt [DateTime]::Now.AddDays( -1 ) } | format-table username,lastlogindate

UserName                                                             IsApproved LastLoginDate
--------                                                             ---------- -------------
user00000003                                                              False 7/24/2010 8:56:38 PM
user00000004                                                               True 7/24/2010 8:49:25 PM
user00000005                                                              False 7/24/2010 9:17:37 PM

Filtering Users by Locked-Out Status

PS> dir users: | where { $_.IsLockedOut } | select username

UserName
--------
user00000004
user00000005

Unlocking All Locked Out Users

PS> dir users: | where { $_.IsLockedOut } | foreach{ $_.UnlockUser(); $_; } | set-item;

Creating a Serial Batch of Test Users

PS> @( 1..100 ) | foreach { new-item users:/testuser$_ -password 'TestPassword123' -email "test$_@test.com" }



PSPath                  : Membership::testuser1
PSDrive                 : users
PSProvider              : Membership
PSIsContainer           : False
UserName                : testuser1
ProviderUserKey         : 4d6366af-b898-48ec-9be2-72902636252e
Email                   : test1@test.com
PasswordQuestion        :
Comment                 :
IsApproved              : True
IsLockedOut             : False
LastLockoutDate         : 1/1/1754 12:00:00 AM
CreationDate            : 7/25/2010 12:35:37 AM
LastLoginDate           : 7/25/2010 12:35:37 AM
LastActivityDate        : 7/25/2010 12:35:37 AM
LastPasswordChangedDate : 7/25/2010 12:35:37 AM
IsOnline                : True
ProviderName            : AspNetSqlMembershipProvider

PSPath                  : Membership::testuser2
PSDrive                 : users
PSProvider              : Membership
...

Use Native UserName Filtering to Remove the Test Users

PS>remove-item users:/ -filter 'testuser%';

Last edited Jul 27, 2010 at 1:30 PM by beefarino, version 7

Comments

No comments yet.