Last active
December 21, 2015 22:19
-
-
Save jbristowe/6374328 to your computer and use it in GitHub Desktop.
PowerShell script for getting all users from a particular Sitefinity site.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-AllUsers { | |
param ( | |
[string] $siteUrl = "", | |
[string] $username = "", | |
[string] $password = "" | |
) | |
if ($siteUrl -eq "") | |
{ | |
$siteUrl = Read-Host "Site URL"; | |
} | |
if ($username -eq "") | |
{ | |
$username = Read-Host "Username" | |
} | |
if ($password -eq "") | |
{ | |
$password = Read-Host "Password" | |
} | |
function isHttpUri($address) { | |
$uri = $address -as [System.URI] | |
$uri.AbsoluteURI -ne $null -and $uri.Scheme -match '[http|https]' | |
} | |
if (-Not (isHttpUri($siteUrl))) { | |
Write-Host "Invalid URL. Exiting." | |
} | |
$jsonContextType = "application/json" | |
$sitefinityUsersService = "Sitefinity/Services/Security/Users.svc" | |
$authenticateMethod = $siteUrl + $sitefinityUsersService + "/Authenticate" | |
$forceLogoutMethod = $siteUrl + $sitefinityUsersService + "/ForceLogout" | |
$logoutWithCredentialsMethod = $siteUrl + $sitefinityUsersService + "/LogoutCredentials" | |
$getAllUsersMethod = $siteUrl + $sitefinityUsersService + "/all" | |
$logoutParameters = "{""UserName"":""" + $userName + """,""Password"":""" + $username + """}" | |
$authenticationParameters = "{""MembershipProvider"":"""",""UserName"":""" + $userName + """,""Password"":""" + $password + """}" | |
$logoutWithCredentialsMethodResponse = Invoke-WebRequest $logoutWithCredentialsMethod -Method Post -ContentType $jsonContextType -Body $authenticationParameters | |
$authenticateMethodResponse = Invoke-RestMethod $authenticateMethod -Method Post -ContentType $jsonContextType -Body $authenticationParameters -SessionVariable session | |
$getAllUsersMethodResponse = Invoke-WebRequest $getAllUsersMethod -ContentType $jsonContextType -WebSession $session | |
($getAllUsersMethodResponse.Content | ConvertFrom-Json).Items | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment