<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Anuj Chaudhary</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/anujchaudhary/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/anujchaudhary/feed.xml</link>
    <description>Software Engineering</description>
    <lastBuildDate>Wed, 17 Apr 2019 03:39:44 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>PowerShell sample for Privileged Identity Management (PIM) for Azure AD Roles</title>
      <link>https://docs.microsoft.com/archive/blogs/anujchaudhary/powershell-sample-for-privileged-identity-management-pim-for-azure-ad-roles</link>
      <pubDate>Thu, 07 Jun 2018 18:24:13 GMT</pubDate>
      <dc:creator><![CDATA[AnujChaudhary]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anujchaudhary/?p=135</guid>
      <description><![CDATA[PIM for Azure AD Roles provides Just in Time (JIT) capability for Azure AD Roles. See more...]]></description>
      <content:encoded><![CDATA[PIM for Azure AD Roles provides Just in Time (JIT) capability for Azure AD Roles. See more at <a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-privileged-identity-management-getting-started">https://docs.microsoft.com/en-us/azure/active-directory/active-directory-privileged-identity-management-getting-started </a>

How cool would it be if I can use the MSGraph PIM api’s to build custom applications. For example, you have multiple roles where you want to activate every day. It would be time consuming to activate them one by one. Instead, you can build a custom app using PowerShell or UI so that you can activate to all of these roles in one shot.

In this blog, I will share a sample to list all your eligible roles and activate or deactivate them. You will also be able to assign someone to a role.

I will share the full source code so you can customize it to suit your needs. Just save this as a .ps1 file and run it with PowerShell.

Note: There is a limitation with MSGraph PIM api's that it wont work if your role requires MFA which should be fixed soon.

<strong><u>Screenshot</u></strong>

<a href="https://msdnshared.blob.core.windows.net/media/2018/06/aad.png"><img width="1918" height="934" class="alignnone size-full wp-image-145" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/06/aad.png" /></a>

<span style="text-decoration: underline"><strong>Setup</strong></span>
<ul>
 	<li>Create a native AAD application. See <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications</a>
<ul>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/native.png"><img width="599" height="213" class="alignnone size-full wp-image-95" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/native.png" /></a></li>
</ul>
</li>
 	<li>Grant it the following permissions to the application.
<ul>
 	<li>Read and write privileged access to Azure AD - You will need it if you are going to use the app for PIM for Azure AD Roles</li>
 	<li>Read and write privileged access to Azure resources - You will need it if you are going to use the app for PIM for Azure Resources</li>
 	<li>Read directory data - You will need it if you are going to read users, etc. from directory like the assignment example in the below source code</li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/permissions.png"><img width="1474" height="481" class="alignnone size-full wp-image-105" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/permissions.png" /></a></li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/perm2.png"><img width="1485" height="567" class="alignnone size-full wp-image-115" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/perm2.png" /></a></li>
 	<li>Note than these permissions require Admin consent so you will have to contact the tenant admin to grant these permissions. See <a href="https://docs.microsoft.com/en-us/azure/active-directory/application-dev-registration-config-grant-permissions-how-to">https://docs.microsoft.com/en-us/azure/active-directory/application-dev-registration-config-grant-permissions-how-to </a></li>
</ul>
</li>
 	<li>In the below code, update $clientID with your application id and $redirectUri with the redirect uri of the application.</li>
</ul>
<strong><u>Source code</u></strong>

#Loads Active Directory Authentication Library
function Load-ActiveDirectoryAuthenticationLibrary(){
$moduleDirPath = [Environment]::GetFolderPath("MyDocuments") + "\WindowsPowerShell\Modules"
$modulePath = $moduleDirPath + "\AADGraph"

if(-not (Test-Path ($modulePath+"\Nugets"))) {New-Item -Path ($modulePath+"\Nugets") -ItemType "Directory" | out-null}
$adalPackageDirectories = (Get-ChildItem -Path ($modulePath+"\Nugets") -Filter "Microsoft.IdentityModel.Clients.ActiveDirectory*" -Directory)

if($adalPackageDirectories.Length -eq 0){
Write-Host "Active Directory Authentication Library Nuget doesn't exist. Downloading now ..." -ForegroundColor Yellow
if(-not(Test-Path ($modulePath + "\Nugets\nuget.exe")))
{
Write-Host "nuget.exe not found. Downloading from https://www.nuget.org/nuget.exe ..." -ForegroundColor Yellow
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("https://www.nuget.org/nuget.exe",$modulePath + "\Nugets\nuget.exe");
}
$nugetDownloadExpression = $modulePath + "\Nugets\nuget.exe install Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.14.201151115 -OutputDirectory " + $modulePath + "\Nugets | out-null"
Invoke-Expression $nugetDownloadExpression
}

$adalPackageDirectories = (Get-ChildItem -Path ($modulePath+"\Nugets") -Filter "Microsoft.IdentityModel.Clients.ActiveDirectory*" -Directory)
$ADAL_Assembly = (Get-ChildItem "Microsoft.IdentityModel.Clients.ActiveDirectory.dll" -Path $adalPackageDirectories[$adalPackageDirectories.length-1].FullName -Recurse)
$ADAL_WindowsForms_Assembly = (Get-ChildItem "Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" -Path $adalPackageDirectories[$adalPackageDirectories.length-1].FullName -Recurse)
if($ADAL_Assembly.Length -gt 0 -and $ADAL_WindowsForms_Assembly.Length -gt 0){
Write-Host "Loading ADAL Assemblies ..." -ForegroundColor Green
[System.Reflection.Assembly]::LoadFrom($ADAL_Assembly[0].FullName) | out-null
[System.Reflection.Assembly]::LoadFrom($ADAL_WindowsForms_Assembly.FullName) | out-null
return $true
}
else{
Write-Host "Fixing Active Directory Authentication Library package directories ..." -ForegroundColor Yellow
$adalPackageDirectories | Remove-Item -Recurse -Force | Out-Null
Write-Host "Not able to load ADAL assembly. Delete the Nugets folder under" $modulePath ", restart PowerShell session and try again ..."
return $false
}
}

#Acquire AAD token
function AcquireToken($mfa){
$clientID = "dabc52c4-106b-4179-9df2-2f791f44ba14"
$redirectUri = "https://pimmsgraph"

$authority = "https://login.microsoftonline.com/common"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority,$false
if($mfa)
{
$authResult = $authContext.AcquireToken("https://graph.microsoft.com",$ClientID,$redirectUri,[Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto, [Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier]::AnyUser, "amr_values=mfa")
Set-Variable -Name mfaDone -Value $true -Scope Global
}
else
{
$authResult = $authContext.AcquireToken("https://graph.microsoft.com",$ClientID,$redirectUri,[Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always)
}
if($authResult -ne $null)
{
Write-Host "User logged in successfully ..." -ForegroundColor Green
}
Set-Variable -Name headerParams -Value @{'Authorization'="$($authResult.AccessTokenType) $($authResult.AccessToken)"} -Scope Global
Set-Variable -Name assigneeId -Value $authResult.UserInfo.UniqueId -Scope Global
}

#Gets my jit assignments
function MyJitAssignments(){
$url = $serviceRoot + "privilegedRoleAssignments/my?`$expand=roleInfo&amp;`$filter=isElevated+eq+false"

Write-Host $url
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$assignments = ConvertFrom-Json $response.Content
Write-Host ""
Write-Host "Role assignments..." -ForegroundColor Green
$i = 0
$obj = @()
foreach ($assignment in $assignments.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleAssignmentId = $assignment.id
RoleId = $assignment.roleInfo.id
RoleName = $assignment.roleInfo.name
UserId = $assignment.userid
}
$obj = $obj + $item
}

return $obj
}

#Gets my active assignments
function MyActivatedAssignments(){
$url = $serviceRoot + "privilegedRoleAssignments/my?`$expand=roleInfo&amp;`$filter=isElevated+eq+true+and+expirationDateTime+ne+null"

Write-Host $url
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$assignments = ConvertFrom-Json $response.Content
Write-Host ""
Write-Host "Role assignments..." -ForegroundColor Green
$i = 0
$obj = @()
foreach ($assignment in $assignments.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleAssignmentId = $assignment.id
RoleId = $assignment.roleInfo.id
RoleName = $assignment.roleInfo.name
UserId = $assignment.userid
ExpirationDateTime = $assignment.expirationDateTime
}
$obj = $obj + $item
}

return $obj
}

#List roles
function ListRoles(){
$url = $serviceRoot + "privilegedRoles?&amp;`$orderby=name"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$roles = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($role in $roles.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleId = $role.id
RoleName = $role.name
}
$obj = $obj + $item
}

return $obj
}

#List Assignment
function ListAssignmentsWithFilter($roleId){
$url = $serviceRoot + "privilegedRoleAssignments?`$expand=roleInfo&amp;`$filter=roleId+eq+'" + $roleId + "'"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$roleAssignments = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($roleAssignment in $roleAssignments.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleAssignmentId = $roleAssignment.id
RoleId = $roleAssignment.roleInfo.id
RoleName = $roleAssignment.roleInfo.name
IsElevated = $roleAssignment.isElevated
ExpirationDateTime = $roleAssignment.expirationDateTime
UserId = $roleAssignment.userId
}
$obj = $obj + $item
}

return $obj
}

#List Users
function ListUsers($user_search){
$url = $MSGraphRoot + "users?`$filter=startswith(displayName,'" + $user_search + "')"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$users = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($user in $users.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
UserId = $user.id
UserName = $user.DisplayName
}
$obj = $obj + $item
}

return $obj
}

#Activates the user
function Activate($isRecursive = $false){
if($isRecursive -eq $false)
{
$assignments = MyJitAssignments
$assignments | Format-Table -AutoSize -Wrap Id,RoleName
$choice = Read-Host "Enter Id to activate"
$hours = Read-Host "Enter Activation duration in hours"
$reason = Read-Host "Enter Reason"
}

$roleId = $assignments[$choice-1].RoleId
$url = $serviceRoot + "privilegedRoles('" + $roleId + "')/selfActivate"
$postParams = '{"duration":"' + $hours + '","reason":"' + $reason + '"}'
write-Host $postParams

try
{
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json" -Body $postParams
Write-Host "Role activated successfully ..." -ForegroundColor Green
}
catch
{
$stream = $_.Exception.Response.GetResponseStream()
$stream.Position = 0;
$streamReader = New-Object System.IO.StreamReader($stream)
$err = $streamReader.ReadToEnd()
$streamReader.Close()
$stream.Close()

if($mfaDone -eq $false -and $err.Contains("MfaRule"))
{
Write-Host "Prompting the user for mfa ..." -ForegroundColor Green
AcquireToken true
Activate $true
}
else
{
Write-Host $err -ForegroundColor Red
}
}
}

#Deactivates the user
function Deactivate($isRecursive = $false){
if($isRecursive -eq $false)
{
$assignments = MyActivatedAssignments
$assignments | Format-Table -AutoSize -Wrap Id,RoleName,ExpirationDateTime
$choice = Read-Host "Enter Id to deactivate"
}

$roleId = $assignments[$choice-1].RoleId
$url = $serviceRoot + "privilegedRoles('" + $roleId + "')/selfDeactivate"
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json"
Write-Host "Role deactivated successfully ..." -ForegroundColor Green
}

#List RoleAssignment
function ListAssignment(){
#List and Pick a role
$roles = ListRoles
$roles | Format-Table -AutoSize -Wrap Id, RoleName, RoleId
$role_choice = Read-Host "Pick a role Id"
$roleId = $roles[$role_choice-1].RoleId
write-Host $roleId

#List Member
$roleAssignments = ListAssignmentsWithFilter $roleId
$roleAssignments | Format-Table -AutoSize -Wrap Id, RoleName, UserId, IsElevated, ExpirationDateTime
}

#Assign a user to Eligible
function AssignmentEligible() {
#List and Pick a role
$roles = ListRoles
$roles | Format-Table -AutoSize -Wrap Id, RoleName
$role_choice = Read-Host "Pick a role Id"
$roleId = $roles[$role_choice-1].RoleId
write-Host $roleId

#Search user by Name, and pick a user
$user_search = Read-Host "user Name start with..."
$users = ListUsers($user_search)
$users | Format-Table -AutoSize -Wrap Id, UserName, UserId
$user_choice = Read-Host "Pick a user Id"
$userId = $users[$user_choice-1].UserId

&nbsp;

$url = $serviceRoot + "privilegedRoleAssignments"
$postParams = '{"roleId":"' + $roleId + '","userId":"' + $userId + '"}'
write-Host $postParams

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json" -Body $postParams
Write-Host "Assignment added successfully ..." -ForegroundColor Green
}

&nbsp;

#Show menu
function ShowMenu(){
Write-Host ""
Write-Host "Azure AD JIT - PowerShell Menu v1.0"
Write-Host " 1. List your eligible role assignments"
Write-Host " 2. Activate an eligible role"
Write-Host " 3. Deactivate an active role"
Write-Host " 4. List Assignment against a role"
Write-Host " 5. Assign a user to a role"
Write-Host " 6. Exit"
}

############################################################################################################################################################################

$global:serviceRoot = "https://graph.microsoft.com/beta/"
$global:MSGraphRoot = "https://graph.microsoft.com/v1.0/"
$global:headerParams = ""
$global:assigneeId = ""
$global:mfaDone = $false;

Load-ActiveDirectoryAuthenticationLibrary
AcquireToken

do
{
ShowMenu
#Write-Host "Enter your selection"
$input = Read-Host "Enter your selection"
switch ($input)
{
'1'
{
$assignments = MyJitAssignments
$assignments | Format-Table -AutoSize -Wrap Id,RoleName
}
'2'
{
Activate
}
'3'
{
Deactivate
}
'4'
{
ListAssignment
}
'5'
{
AssignmentEligible
}
'6'
{
return
}
}
}
until ($input -eq '6')

Write-Host ""]]></content:encoded>
    </item>
    <item>
      <title>Securing Azure resources with Privileged Identity Management</title>
      <link>https://docs.microsoft.com/archive/blogs/anujchaudhary/securing-azure-resources-with-privileged-identity-management</link>
      <pubDate>Thu, 12 Apr 2018 01:13:24 GMT</pubDate>
      <dc:creator><![CDATA[AnujChaudhary]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anujchaudhary/?p=65</guid>
      <description><![CDATA[With Azure Active Directory Privileged Identity Management (PIM), you can now manage, control, and...]]></description>
      <content:encoded><![CDATA[With Azure Active Directory Privileged Identity Management (PIM), you can now manage, control, and monitor access to Azure Resources within your organization. To learn more, see <a href="https://docs.microsoft.com/en-us/azure/active-directory/privileged-identity-management/azure-pim-resource-rbac">https://docs.microsoft.com/en-us/azure/active-directory/privileged-identity-management/azure-pim-resource-rbac</a>

It is important to have a Just In Time (JIT) capability to JIT into an Azure subscription for few hours to investigate any issues. However, once a bad guy has access to the subscription, he can get a lot of information out (like secrets, etc.) and do bad things even after the access is lost.

With PIM, you can assign JIT access not only at the subscription level but also at a specific Resource group or Resource level to prevent any information disclosure. Here is an example of how you can manage your subscription securely with PIM.

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Capture.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/04/Capture.png" alt="" width="686" height="219" class="alignnone size-full wp-image-75" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/Capture.png"></a>

Create a Resource group for all your secrets. Let’s call it SecretsResourceGroup. This resource group can have the following resources:
<ul>
 	<li>Azure Storage</li>
 	<li>SQL Azure</li>
 	<li>Cosmos DB</li>
 	<li>Etc.</li>
</ul>
Create a Resource group for all your deployments. Let’s call it DeploymentsResourceGroup. This resource can have the following resources:
<ul>
 	<li>Cloud Service</li>
 	<li>Service Fabric</li>
 	<li>App Service</li>
 	<li>Virtual Machines</li>
 	<li>Etc.</li>
</ul>
You will notice that almost anyone who needs access to the subscription actually needs access to a resource within DeploymentsResourceGroup. Typical scenarios include:
<ul>
 	<li>Investigating live site issue with a specific deployment</li>
 	<li>Restarting a VM</li>
 	<li>Installing a software update</li>
 	<li>Etc.</li>
</ul>
If they need access to multiple resources, you can assign them Eligible assignment on the Resource group. If they need access to a specific resource, you can assign them Eligible assignment on the specific resource. Now whenever, they need access, they can JIT into the specific resource at that time. You can also configure approval so that they can only JIT upon approval.

Thus, due to the granularity that PIM supports, you can now prevent people from accessing your secrets but still allow them to JIT into the specific resources where they need to investigate any issues.]]></content:encoded>
    </item>
    <item>
      <title>PowerShell sample for Privileged Identity Management (PIM) for Azure Resources</title>
      <link>https://docs.microsoft.com/archive/blogs/anujchaudhary/powershell-sample-for-privileged-identity-management-pim-for-azure-resources</link>
      <pubDate>Wed, 07 Feb 2018 04:01:38 GMT</pubDate>
      <dc:creator><![CDATA[AnujChaudhary]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anujchaudhary/?p=36</guid>
      <description><![CDATA[PIM for Azure Resources provides Just in Time (JIT) and Temporary access capabilities for Azure...]]></description>
      <content:encoded><![CDATA[PIM for Azure Resources provides Just in Time (JIT) and Temporary access capabilities for Azure Resources. See more at <a href="https://docs.microsoft.com/en-us/azure/active-directory/privileged-identity-management/azure-pim-resource-rbac">https://docs.microsoft.com/en-us/azure/active-directory/privileged-identity-management/azure-pim-resource-rbac</a>

How cool would it be if I can use the MSGraph PIM api’s to build custom applications. For example, your IT Org has N different resource groups where you want to activate every day. It would be time consuming to activate them one by one. Instead, you can build a custom app using PowerShell or UI so that you can activate to all of these resource groups in one shot.

In this blog, I will share a sample to list all your eligible roles and activate or deactivate them. You will also be able to assign someone to a role.

I will share the full source code so you can customize it to suit your needs. Just save this as a .ps1 file and run it with PowerShell.

Note: There is a limitation with MSGraph PIM api's that it wont work if your role requires MFA which should be fixed soon.

<strong><u>Screenshot</u></strong>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/rbac.png"><img width="1918" height="1031" class="alignnone size-full wp-image-125" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/rbac.png" /></a>

<span style="text-decoration: underline"><strong>Setup</strong></span>
<ul>
 	<li>Create a native AAD application. See <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications</a>
<ul>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/native.png"><img width="599" height="213" class="alignnone size-full wp-image-95" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/native.png" /></a></li>
</ul>
</li>
 	<li>Grant it the following permissions to the application.
<ul>
 	<li>Read and write privileged access to Azure AD - You will need it if you are going to use the app for PIM for Azure AD Roles</li>
 	<li>Read and write privileged access to Azure resources - You will need it if you are going to use the app for PIM for Azure Resources</li>
 	<li>Read directory data - You will need it if you are going to read users, etc. from directory like the assignment example in the below source code</li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/permissions.png"><img width="1474" height="481" class="alignnone size-full wp-image-105" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/permissions.png" /></a></li>
 	<li><a href="https://msdnshared.blob.core.windows.net/media/2018/02/perm2.png"><img width="1485" height="567" class="alignnone size-full wp-image-115" alt="" src="https://msdnshared.blob.core.windows.net/media/2018/02/perm2.png" /></a></li>
 	<li>Note than these permissions require Admin consent so you will have to contact the tenant admin to grant these permissions. See <a href="https://docs.microsoft.com/en-us/azure/active-directory/application-dev-registration-config-grant-permissions-how-to">https://docs.microsoft.com/en-us/azure/active-directory/application-dev-registration-config-grant-permissions-how-to </a></li>
</ul>
</li>
 	<li>In the below code, update $clientID with your application id and $redirectUri with the redirect uri of the application.</li>
</ul>
<strong><u>Source code</u></strong>

#Loads Active Directory Authentication Library
function Load-ActiveDirectoryAuthenticationLibrary(){
$moduleDirPath = [Environment]::GetFolderPath("MyDocuments") + "\WindowsPowerShell\Modules"
$modulePath = $moduleDirPath + "\AADGraph"

if(-not (Test-Path ($modulePath+"\Nugets"))) {New-Item -Path ($modulePath+"\Nugets") -ItemType "Directory" | out-null}
$adalPackageDirectories = (Get-ChildItem -Path ($modulePath+"\Nugets") -Filter "Microsoft.IdentityModel.Clients.ActiveDirectory*" -Directory)

if($adalPackageDirectories.Length -eq 0){
Write-Host "Active Directory Authentication Library Nuget doesn't exist. Downloading now ..." -ForegroundColor Yellow
if(-not(Test-Path ($modulePath + "\Nugets\nuget.exe")))
{
Write-Host "nuget.exe not found. Downloading from https://www.nuget.org/nuget.exe ..." -ForegroundColor Yellow
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("https://www.nuget.org/nuget.exe",$modulePath + "\Nugets\nuget.exe");
}
$nugetDownloadExpression = $modulePath + "\Nugets\nuget.exe install Microsoft.IdentityModel.Clients.ActiveDirectory -Version 2.14.201151115 -OutputDirectory " + $modulePath + "\Nugets | out-null"
Invoke-Expression $nugetDownloadExpression
}

$adalPackageDirectories = (Get-ChildItem -Path ($modulePath+"\Nugets") -Filter "Microsoft.IdentityModel.Clients.ActiveDirectory*" -Directory)
$ADAL_Assembly = (Get-ChildItem "Microsoft.IdentityModel.Clients.ActiveDirectory.dll" -Path $adalPackageDirectories[$adalPackageDirectories.length-1].FullName -Recurse)
$ADAL_WindowsForms_Assembly = (Get-ChildItem "Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll" -Path $adalPackageDirectories[$adalPackageDirectories.length-1].FullName -Recurse)
if($ADAL_Assembly.Length -gt 0 -and $ADAL_WindowsForms_Assembly.Length -gt 0){
Write-Host "Loading ADAL Assemblies ..." -ForegroundColor Green
[System.Reflection.Assembly]::LoadFrom($ADAL_Assembly[0].FullName) | out-null
[System.Reflection.Assembly]::LoadFrom($ADAL_WindowsForms_Assembly.FullName) | out-null
return $true
}
else{
Write-Host "Fixing Active Directory Authentication Library package directories ..." -ForegroundColor Yellow
$adalPackageDirectories | Remove-Item -Recurse -Force | Out-Null
Write-Host "Not able to load ADAL assembly. Delete the Nugets folder under" $modulePath ", restart PowerShell session and try again ..."
return $false
}
}

#Acquire AAD token
function AcquireToken($mfa){
$clientID = "dabc52c4-106b-4179-9df2-2f791f44ba14"
$redirectUri = "https://pimmsgraph"

$authority = "https://login.microsoftonline.com/common"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority,$false
if($mfa)
{
$authResult = $authContext.AcquireToken("https://graph.microsoft.com",$ClientID,$redirectUri,[Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto, [Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier]::AnyUser, "amr_values=mfa")
Set-Variable -Name mfaDone -Value $true -Scope Global
}
else
{
$authResult = $authContext.AcquireToken("https://graph.microsoft.com",$ClientID,$redirectUri,[Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always)
}
if($authResult -ne $null)
{
Write-Host "User logged in successfully ..." -ForegroundColor Green
}
Set-Variable -Name headerParams -Value @{'Authorization'="$($authResult.AccessTokenType) $($authResult.AccessToken)"} -Scope Global
Set-Variable -Name assigneeId -Value $authResult.UserInfo.UniqueId -Scope Global
}

#Gets my jit assignments
function MyJitAssignments(){
$urlme = $global:MSGraphRoot + "me/"
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $urlme -Method Get
$me = ConvertFrom-Json $response.Content
$subjectId = $me.id
Write-Host $subjectId

$url = $serviceRoot + "roleAssignments?`$expand=linkedEligibleRoleAssignment,subject,roleDefinition(`$expand=resource)&amp;`$filter=(assignmentState+eq+'Eligible')+and+(subjectId+eq+'" + $subjectId + "')"

Write-Host $url
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$assignments = ConvertFrom-Json $response.Content
Write-Host ""
Write-Host "Role assignments..." -ForegroundColor Green
$i = 0
$obj = @()
foreach ($assignment in $assignments.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleAssignmentId = $assignment.id
ResourceId = $assignment.roleDefinition.resource.id
OriginalId = $assignment.roleDefinition.resource.externalId
ResourceName = $assignment.roleDefinition.resource.displayName
ResourceType = $assignment.roleDefinition.resource.type
RoleId = $assignment.roleDefinition.id
RoleName = $assignment.roleDefinition.displayName
ExpirationDate = $assignment.endDateTime
SubjectId = $assignment.subject.id
}
$obj = $obj + $item
}

return $obj
}

#List resources
function ListResources(){
$url = $serviceRoot + "resources?`$filter=(type+eq+'subscription')"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$resources = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($resource in $resources.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
ResourceId = $resource.id
ResourceName = $resource.DisplayName
Type = $resource.type
ExternalId = $resource.externalId
}
$obj = $obj + $item
}

return $obj
}

#List roles
function ListRoles($resourceId){
$url = $serviceRoot + "resources/" + $resourceId + "/roleDefinitions?&amp;`$orderby=displayName"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$roles = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($role in $roles.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleDefinitionId = $role.id
RoleName = $role.DisplayName
}
$obj = $obj + $item
}

return $obj
}

#List Assignment
function ListAssignmentsWithFilter($resourceId, $roleDefinitionId){
$url = $serviceRoot + "resources/" + $resourceId + "`/roleAssignments?`$expand=subject,roleDefinition(`$expand=resource)&amp;`$filter=(roleDefinition/id+eq+'" + $roleDefinitionId + "')"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$roleAssignments = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($roleAssignment in $roleAssignments.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
RoleAssignmentId = $roleAssignment.id
ResourceId = $roleAssignment.roleDefinition.resource.id
OriginalId = $roleAssignment.roleDefinition.resource.externalId
ResourceName = $roleAssignment.roleDefinition.resource.displayName
ResourceType = $roleAssignment.roleDefinition.resource.type
RoleId = $roleAssignment.roleDefinition.id
RoleName = $roleAssignment.roleDefinition.displayName
ExpirationDate = $roleAssignment.endDateTime
SubjectId = $roleAssignment.subject.id
UserName = $roleAssignment.subject.displayName
AssignmentState = $roleAssignment.AssignmentState
}
$obj = $obj + $item
}

return $obj
}

#List Users
function ListUsers($user_search){
$url = $MSGraphRoot + "users?`$filter=startswith(displayName,'" + $user_search + "')"
Write-Host $url

$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Get
$users = ConvertFrom-Json $response.Content
$i = 0
$obj = @()
foreach ($user in $users.value)
{
$item = New-Object psobject -Property @{
Id = ++$i
UserId = $user.id
UserName = $user.DisplayName
}
$obj = $obj + $item
}

return $obj
}

#Activates the user
function Activate($isRecursive = $false){
if($isRecursive -eq $false)
{
$assignments = MyJitAssignments
$assignments | Format-Table -AutoSize -Wrap Id,RoleName,ResourceName,ResourceType,ExpirationDate
$choice = Read-Host "Enter Id to activate"
[int]$hours = Read-Host "Enter Activation duration in hours"
$reason = Read-Host "Enter Reason"
}

$id = $assignments[$choice-1].RoleAssignmentId
$resourceId = $assignments[$choice-1].ResourceId
$roleDefinitionId = $assignments[$choice-1].RoleId
$subjectId = $assignments[$choice-1].SubjectId
$url = $serviceRoot + "roleAssignmentRequests"
$postParams = '{"id":"00000000-0000-0000-0000-000000000000","assignmentState":"Active","type":"UserAdd","reason":"' + $reason + '","roleDefinitionId":"' + $roleDefinitionId + '","resourceId":"' + $resourceId + '","subjectId":"' + $subjectId + '","schedule":{"duration":"PT' + $hours + 'H","startDateTime":"' + (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + '","type":"Once"},"linkedEligibleRoleAssignmentId":"' + $id + '"}'
write-Host $postParams

try
{
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json" -Body $postParams
Write-Host "Activation request queued successfully ..." -ForegroundColor Green
}
catch
{
$stream = $_.Exception.Response.GetResponseStream()
$stream.Position = 0;
$streamReader = New-Object System.IO.StreamReader($stream)
$err = $streamReader.ReadToEnd()
$streamReader.Close()
$stream.Close()

if($mfaDone -eq $false -and $err.Contains("MfaRule"))
{
Write-Host "Prompting the user for mfa ..." -ForegroundColor Green
AcquireToken true
Activate $true
}
else
{
Write-Host $err -ForegroundColor Red
}
}
}

#Deactivates the user
function Deactivate($isRecursive = $false){
if($isRecursive -eq $false)
{
$assignments = MyJitAssignments
$assignments | Format-Table -AutoSize -Wrap id,RoleName,ResourceName,ResourceType,ExpirationDate
$choice = Read-Host "Enter Id to deactivate"
}

$id = $assignments[$choice-1].RoleAssignmentId
$resourceId = $assignments[$choice-1].ResourceId
$roleDefinitionId = $assignments[$choice-1].RoleId
$subjectId = $assignments[$choice-1].SubjectId
$url = $serviceRoot + "roleAssignmentRequests"
$postParams = '{"assignmentState":"Active","type":"UserRemove","roleDefinitionId":"' + $roleDefinitionId + '","resourceId":"' + $resourceId + '","subjectId":"' + $subjectId + '"}'
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json" -Body $postParams
Write-Host "Role deactivated successfully ..." -ForegroundColor Green
}

#List RoleAssignment
function ListAssignment(){
#List and Pick resource
$resources = ListResources
$resources | Format-Table -AutoSize -Wrap Id, ResourceName, Type, ExternalId
$res_choice = Read-Host "Pick an resource Id for assigment"
$resourceId = $resources[$res_choice-1].ResourceId

#List and Pick a role
$roles = ListRoles($resourceId)
$roles | Format-Table -AutoSize -Wrap Id, RoleName, RoleDefinitionId
$role_choice = Read-Host "Pick a role Id"
$roleDefinitionId = $roles[$role_choice-1].RoleDefinitionId
write-Host $roleDefinitionId

#List Member
$roleAssignments = ListAssignmentsWithFilter $resourceId $roleDefinitionId
$roleAssignments | Format-Table -AutoSize -Wrap Id, ResourceName, ResourceType, RoleName, UserName, AssignmentState, ExpirationDate
}

#Assign a user to Eligible
function AssignmentEligible() {
#List and Pick resource
$resources = ListResources
$resources | Format-Table -AutoSize -Wrap Id, ResourceName, Type, ExternalId
$res_choice = Read-Host "Pick an resource Id for assigment"
$resourceId = $resources[$res_choice-1].ResourceId

#List and Pick a role
$roles = ListRoles($resourceId)
$roles | Format-Table -AutoSize -Wrap Id, RoleName, RoleDefinitionId
$role_choice = Read-Host "Pick a role Id"
$roleDefinitionId = $roles[$role_choice-1].RoleDefinitionId
write-Host $roleDefinitionId

#Search user by Name, and pick a user
$user_search = Read-Host "user Name start with..."
$users = ListUsers($user_search)
$users | Format-Table -AutoSize -Wrap Id, UserName, UserId
$user_choice = Read-Host "Pick a user Id"
$subjectId = $users[$user_choice-1].UserId

&nbsp;

$url = $serviceRoot + "roleAssignmentRequests"
# Update end time
$ts = New-TimeSpan -Days 30
$postParams = '{"assignmentState":"Eligible","type":"AdminAdd","reason":"Assign","roleDefinitionId":"' + $roleDefinitionId + '","resourceId":"' + $resourceId + '","subjectId":"' + $subjectId + '","schedule":{"startDateTime":"' + (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + '","endDateTime":"' + ((get-date) + $ts).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ") + '","type":"Once"}}'
write-Host $postParams

try
{
$response = Invoke-WebRequest -UseBasicParsing -Headers $headerParams -Uri $url -Method Post -ContentType "application/json" -Body $postParams
Write-Host "Assignment request queued successfully ..." -ForegroundColor Green
}
catch
{
$stream = $_.Exception.Response.GetResponseStream()
$stream.Position = 0;
$streamReader = New-Object System.IO.StreamReader($stream)
$err = $streamReader.ReadToEnd()
$streamReader.Close()
$stream.Close()

if($mfaDone -eq $false -and $err.Contains("MfaRule"))
{
Write-Host "Prompting the user for mfa ..." -ForegroundColor Green
AcquireToken true
Activate $true
}
else
{
Write-Host $err -ForegroundColor Red
}
}
}

#Show menu
function ShowMenu(){
Write-Host ""
Write-Host "Azure RBAC JIT - PowerShell Menu v1.0"
Write-Host " 1. List your eligible role assignments"
Write-Host " 2. Activate an eligible role"
Write-Host " 3. Deactivate an active role"
Write-Host " 4. List Assignment against a resource"
Write-Host " 5. Assign a user to a role"
Write-Host " 6. Exit"
}

############################################################################################################################################################################

$global:serviceRoot = "https://graph.microsoft.com/beta/privilegedAccess/azureResources/"
$global:MSGraphRoot = "https://graph.microsoft.com/v1.0/"
$global:headerParams = ""
$global:assigneeId = ""
$global:mfaDone = $false;

Load-ActiveDirectoryAuthenticationLibrary
AcquireToken

do
{
ShowMenu
#Write-Host "Enter your selection"
$input = Read-Host "Enter your selection"
switch ($input)
{
'1'
{
$assignments = MyJitAssignments
$assignments | Format-Table -AutoSize -Wrap id,RoleName,ResourceName,ResourceType,ExpirationDate
}
'2'
{
Activate
}
'3'
{
Deactivate
}
'4'
{
ListAssignment
}
'5'
{
AssignmentEligible
}
'6'
{
return
}
}
}
until ($input -eq '6')

Write-Host ""

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Windows Azure: Automated UI testing using the power of cloud</title>
      <link>https://docs.microsoft.com/archive/blogs/anujchaudhary/windows-azure-automated-ui-testing-using-the-power-of-cloud</link>
      <pubDate>Fri, 02 Nov 2012 15:43:00 GMT</pubDate>
      <dc:creator><![CDATA[AnujChaudhary]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/anujchaudhary/2012/11/02/windows-azure-automated-ui-testing-using-the-power-of-cloud/</guid>
      <description><![CDATA[Problem Statement

Automated UI testing needs to be performed from different parts of the...]]></description>
      <content:encoded><![CDATA[<div>
<p><span style="color: #000000;"><strong><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="font-family: Cambria;">Problem Statement</span></span></span></strong></span></p>
</div>
<p><span style="font-size: small;"><span style="font-family: Calibri;">Automated UI testing needs to be performed from different parts of the world.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">The tests can validate various UI behaviors from different geo locations e.g. behavior of JavaScript which makes service calls.</span></span></p>
<p><span style="color: #000000;"><strong><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="font-family: Cambria;">Background</span></span></span></strong></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">As we have seen in my previous post on <em><a href="https://social.technet.microsoft.com/wiki/contents/articles/6073.windows-azure-performance-testing-using-the-power-of-cloud.aspx"><span style="color: #0000ff;">Performance testing using the power of cloud</span></a></em>, it is possible to install test agents around the globe and run Load Tests from the agents. The same setup can be used to run unit tests or web tests by distributing them across different agents.</span></span></p>
<p><span style="color: #000000; text-decoration: underline;"><strong><span style="text-decoration: underline;"><span style="font-family: Cambria;">Challenge</span></span></strong></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">The challenging part is to run UI tests (e.g. Coded UI) from the agents in cloud. This is because we will always need to have an active desktop session for the tests to interact with the UI. One option would be to have dedicated&nbsp;hardware on premise from where active remote desktop session is always maintained for all the agents in the cloud. The other option is to tweak the configuration a little as described below without requiring any additional hardware.</span></span></p>
<p><span style="color: #000000; text-decoration: underline;"><strong><span style="text-decoration: underline;"><span style="font-family: Cambria;">Solution</span></span></strong></span></p>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Perform the same steps which were done for the setting up the environment to run load tests i.e. Installing Test Controller on Premise and Setting up Windows Azure Connect.</span></span></p>
<p><span style="font-family: Calibri;"><span style="font-size: small;">Now below are the changes that the needed to specifically run Automated UI Tests</span></span></p>
<ul>
<li><span style="font-family: Calibri;"><span style="font-size: small;">Instead of having just one user on the Azure VM&rsquo;s, we will need to have two users. One of them is used for Remote Desktop and the other one is used to Run Tests.</span></span></li>
<li><span style="font-size: small;"><span style="font-family: Calibri;">The Remote Desktop user needs to be specified in the configuration file (.cscfg)</span></span></li>
</ul>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>&lt;</em><em>Setting</em><em> </em><em>name</em><em>=</em><em>"Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountUsername" value="remoteuser" /&gt;</em></span></p>
<ul>
<li><em>&nbsp;</em><span style="font-size: small;"><span style="font-family: Calibri;">The Test Agent user needs to be created in setup.cmd (This user name and password should be the same as the one configured on Test Controller)</span></span></li>
</ul>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REM Create user vstestagent as an administrator</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>net user vstestagent &lt;&lt;password&gt;&gt; /expires:never /add</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>net localgroup administrators vstestagent /Add</em></span></p>
<ul>
<li>&nbsp;<span style="font-size: small;"><span style="font-family: Calibri;">Deploy the worker role and add it to the Local Endpoint Group for Windows Azure Connect as before.</span></span></li>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Now Remote Desktop to the Azure VM from the Azure Portal using the Remote Desktop user.</span></span></li>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Once connected, get the machine name of the VM from Computer-&gt;Properties.</span></span></li>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Go to Run and type mstsc and connect to the same VM using the machine name. While connecting this time, type the credentials of the Test Agent user.</span></span></li>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Configure the test agent with the test controller in Interactive mode.</span></span></li>
</ul>
<p style="padding-left: 60px;"><span style="font-size: small;"><span style="font-family: Calibri;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/1832.1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/1832.1.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/1832.1.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/1832.1.png" alt="" width="300" height="318" border="0" /></a></span></span><span style="font-family: Calibri; font-size: small;">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5224.2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5224.2.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5224.2.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5224.2.png" alt="" width="448" height="316" border="0" /></a></span></p>
<ul>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Finally, a script needs to be run to turn off IE ESC, set default IE settings, turn off Phishing filter and disable Auto Lock. A command file can be added which does the following:</span></span></li>
</ul>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REM Configure IE ESC to Off</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" /v "IsInstalled" /t REG_DWORD /d 0 /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" /v "IsInstalled" /t REG_DWORD /d 0 /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>Rundll32 iesetup.dll, IEHardenLMSettings</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>Rundll32 iesetup.dll, IEHardenUser</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>Rundll32 iesetup.dll, IEHardenAdmin</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" /f /va</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" /f /va</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REM Set Default IE Settings</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG DELETE "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main" /v "First Home Page" /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main" /v "Default_Page_URL" /t REG_SZ /d "about:blank" /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main" /v "Start Page" /t REG_SZ /d "about:blank" /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REM Disable Phishing Filter</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PhishingFilter" /v "ShownVerifyBalloon" /t REG_DWORD /d 3 /f</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\PhishingFilter" /v "Enabled" /t REG_DWORD /d 0 /f </em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REM Disable Auto Lock</em></span></p>
<p style="padding-left: 60px;"><span style="color: #993300; font-size: x-small;"><em>REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v "DisableLockWorkstation" /t REG_DWORD /d 1 /f</em></span></p>
<ul>
<li><span style="font-size: small;"><span style="font-family: Calibri;">Now don&rsquo;t minimize any remote desktop windows and simply close the remote desktop window of the Remote Desktop user. This way the Remote Desktop window of the Test Agent user will be always active and the UI Tests can interact with the desktop.</span></span></li>
</ul>
<p><span style="color: #000000;"><strong><span style="text-decoration: underline;"><span style="text-decoration: underline;"><span style="font-family: Cambria;">Result</span></span></span></strong></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">Now you can run your tests using the Test Controller. The Agent running as an interactive Process should be shown with an asterisk (*)</span></span></p>
<p><span style="font-family: Calibri; font-size: small;">&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5734.3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5734.3.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5734.3.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5734.3.png" alt="" width="365" height="352" border="0" /></a></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">The Automated UI Test runs on the Test Agent</span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5861.4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5861.4.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/56/48/5861.4.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-56-48/5861.4.png" alt="" width="504" height="128" border="0" /></a></span></span></p>
<p><span style="font-size: small;"><span style="font-family: Calibri;">To confirm that the desktop doesn&rsquo;t get locked, wait for 10-15 minutes, rerun the automated UI test and verify that it passes.</span></span></p>
<p><span style="font-family: Calibri; font-size: small;">&nbsp;</span></p>]]></content:encoded>
    </item>
  </channel>
</rss>