Created
August 24, 2016 22:03
-
-
Save 0xfeeddeadbeef/ea3e9d6d2e120b6e246baf7e83a09cb8 to your computer and use it in GitHub Desktop.
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
# This internal function will download latest NetSqlAzMan.dll from NuGet (if necessary) and import it into runspace: | |
function _DownloadAndImportLatestNetSqlAzManDll | |
{ | |
$DownloadUrl = 'https://api.nuget.org/packages/netsqlazman-x64.3.6.0.15.nupkg' | |
$LocalDir = Join-Path $env:TEMP 'NetSqlAzMan' | |
$LocalNupkg = Join-Path $LocalDir 'netsqlazman-x64.3.6.0.15.nupkg' | |
$DllPath = Join-Path $LocalDir 'lib\net40\NetSqlAzMan.dll' | |
if (-not (Test-Path $LocalDir)) { | |
New-Item -Path $LocalDir -ItemType Directory -Force | |
} | |
if (-not (Test-Path $LocalNupkg)) { | |
Invoke-WebRequest -Uri $DownloadUrl -Method Get -OutFile $LocalNupkg | |
} | |
if (-not (Test-Path $DllPath)) { | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($LocalNupkg, $LocalDir) | |
} | |
Add-Type -Path $DllPath | |
} | |
_DownloadAndImportLatestNetSqlAzManDll | |
# Initialization: | |
$ConnectionString = 'Server=MySQLServerHostName; Database=NetSqlAzManStorage; Integrated Security=True' | |
$AppStoreName = 'MyAppStoreName' | |
$AppName = 'MyAppName' | |
$AppGroupName = 'MyAppGroupName' | |
$AzStorage = New-Object NetSqlAzMan.SqlAzManStorage($ConnectionString) | |
$AzStore = $AzStorage.GetStore($AppStoreName) | |
$AzApp = $AzStore.GetApplication($AppName) | |
# Example usage: | |
$AzApp.GetApplicationGroup($AppGroupName).Members | Export-Csv -Path 'MyAppGroupMembers.csv' -NoTypeInformation | |
$Member = $AzApp.GetApplicationGroup($AppGroupName).GetApplicationGroupAllMembers() | Select-Object -First 1 | |
$Member.GetMemberInfo([ref] $MemberName) | |
"Display name of user: $MemberName" | |
# See NetSqlAzMan API reference: http://netsqlazman.codeplex.com/downloads/get/348377 | |
# Cleanup: | |
$AzApp.Dispose() | |
$AzStore.Dispose() | |
$AzStorage.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment