{"action":"created","comment":{"url":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments/89034578","pull_request_review_id":9586764,"id":89034578,"diff_hunk":"@@ -0,0 +1,436 @@\n+﻿[cmdletBinding]\n+Function New-ServicePrincipal\n+{\n+<#\n+.SYNOPSIS\n+This cmdlet helps you create:\n+1) AD Apllication needed for SPN\n+2) AD SPN\n+3) Assigning Reader role to the newly created SPN\n+#>\n+    param(\n+    [Parameter(Mandatory=$true, HelpMessage=\"Azure AD Apllication Display Name\")]\n+    [ValidateNotNullOrEmpty()]\n+    [string]$ADAppDisplayName,\n+    \n+    [Parameter(Mandatory=$true, HelpMessage=\"Azure Subscription Id\")]\n+    [ValidateNotNullOrEmpty()]\n+    [string]$SubscriptionId,\n+    \n+    [Parameter(Mandatory=$false, HelpMessage=\"Azure AD Apllication Display Name\")]\n+    [string]$TenantId = \"72f988bf-86f1-41af-91ab-2d7cd011db47\",\n+\n+    [Parameter(Mandatory=$false, HelpMessage=\"True: AD App is created if does not exist\")]\n+    [bool]$createADAppIfNotFound = $false,\n+\n+    [Parameter(Mandatory=$false, HelpMessage=\"True: AD SPN is created if does not exist\")]\n+    [bool]$createADSpnIfNotFound = $false\n+    \n+    )\n+\n+    Set-Subscription -SubscriptionId $SubscriptionId -TenantId $TenantId\n+\n+    $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName\n+    if($azAdApp -eq $null -and $createADAppIfNotFound -eq $true)\n+    {\n+        $displayName = $ADAppDisplayName\n+        $homePage = \"http://www.$displayName.psmodule\"\n+        $identityUri = \"http://$displayName\"\n+        $azAdApp = New-AzureRmADApplication -DisplayName $displayName -HomePage $homePage -IdentifierUris $identityUri\n+    }\n+\n+    $azSpn = Get-SPN -ADAppId $azAdApp.ApplicationId\n+\n+    if(($azAdApp -ne $null) -and ($azSpn -eq $null))\n+    {\n+        if($createADSpnIfNotFound -eq $true)\n+        {\n+            $azSpn = New-AzureRmADServicePrincipal -ApplicationId $azAdApp.ApplicationId            \n+            Write-Host \"Waiting for SPN to fully create and able to query .....\"\n+\n+            for($i=0; $i -lt 3; $i++)\n+            {\n+                #need to find a better deterministic way\n+                #Cases are when you try to assign roles to newly created SPN, it is not able to find it and hence Role Assignment fails\n+                #Get-SPN -ADAppId $azAdApp.ApplicationId\n+                Start-Sleep -Seconds 5\n+            }\n+        }\n+    }\n+\n+    if($azSpn -ne $null)\n+    {\n+        $spnScope = [string]::Format(\"{0}{1}\", \"/subscriptions/\", \"$SubscriptionId/\")\n+\n+        $rdStr = [string]::Format(\"{0} Role will be assigned to SPNName:{1} for scope {2}\", \"Reader\", $azAdApp.ApplicationId, $spnScope)\n+        Write-Host $rdStr\n+\n+        $roleDef = Get-AzureRmRoleAssignment -ServicePrincipalName $azAdApp.ApplicationId -Scope $spnScope\n+        if($roleDef -eq $null)\n+        {\n+            New-AzureRmRoleAssignment -RoleDefinitionName \"Reader\" -ServicePrincipalName $azAdApp.ApplicationId -scope $spnScope\n+        }\n+    }\n+\n+    Get-ServicePrincipalDetails -AdApp $azAdApp -AdSpn $azSpn\n+\n+    Write-Host \"Log onto Azure Portal and use Above SPN Details to find your Service Principal and obtain SPN Secret/ Authentication Key/ Secret Key for the newly created Service Principal\" -ForegroundColor DarkYellow\n+    Write-Host \"Visit https://docs.microsoft.com/en-us/azure/resource-group-create-service-principal-portal\" -ForegroundColor DarkYellow\n+}\n+\n+Function Get-ADApp\n+{\n+    param(\n+    [Parameter(Mandatory=$true, HelpMessage=\"Azure AD Apllication Display Name\")]\n+    [ValidateNotNullOrEmpty()]\n+    [string]$ADAppDisplayName\n+    )\n+\n+    $displayName = $ADAppDisplayName\n+    $homePage = \"http://www.$displayName.psmodule\"\n+    $identityUri = \"http://$displayName\"\n+\n+    $azAdApp = Get-AzureRmADApplication -IdentifierUri $identityUri\n+\n+    $PsCmdLet.WriteObject($azAdApp)\n+}\n+\n+[CmdletBinding]\n+Function Get-SPN\n+{\n+    param(\n+    [Parameter(Mandatory=$true, ParameterSetName=\"DisplayName\", HelpMessage=\"Azure AD Apllication Display Name\")]\n+    [ValidateNotNullOrEmpty()]\n+    [string]$ADAppDisplayName,\n+\n+    [Parameter(Mandatory=$true, ParameterSetName=\"AppId\", HelpMessage=\"Azure AD Apllication ID\")]\n+    [ValidateNotNullOrEmpty()]\n+    [string]$ADAppId\n+    )\n+\n+    $appId = \"\"\n+    if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $false)\n+    {\n+        $azAdApp = Get-ADApp -ADAppDisplayName $ADAppDisplayName\n+        $appId = $azAdApp.ApplicationId\n+    }\n+    \n+    if([string]::IsNullOrEmpty($ADAppDisplayName) -eq $true)\n+    {\n+        $appId = $ADAppId\n+    }\n+\n+    $azSpn = Get-AzureRmADServicePrincipal -ServicePrincipalName $appId","path":"tools/Modules/TestFx-Tasks.psm1","position":123,"original_position":123,"commit_id":"ec3fb1395e98b684dbf2a295cfb73ba8f4beec23","original_commit_id":"ec3fb1395e98b684dbf2a295cfb73ba8f4beec23","user":{"login":"markcowl","id":1054056,"avatar_url":"https://avatars.githubusercontent.com/u/1054056?v=3","gravatar_id":"","url":"https://api.github.com/users/markcowl","html_url":"https://github.com/markcowl","followers_url":"https://api.github.com/users/markcowl/followers","following_url":"https://api.github.com/users/markcowl/following{/other_user}","gists_url":"https://api.github.com/users/markcowl/gists{/gist_id}","starred_url":"https://api.github.com/users/markcowl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markcowl/subscriptions","organizations_url":"https://api.github.com/users/markcowl/orgs","repos_url":"https://api.github.com/users/markcowl/repos","events_url":"https://api.github.com/users/markcowl/events{/privacy}","received_events_url":"https://api.github.com/users/markcowl/received_events","type":"User","site_admin":false},"body":"Normally you have to create a service principal after creating the appi, see: https://gist.github.com/devigned/dae74a7ca54000f7b714#file-sp-w-cert-azps-1-0-ps1-L30 ","created_at":"2016-11-22T02:47:37Z","updated_at":"2016-11-22T02:50:28Z","html_url":"https://github.com/Azure/azure-powershell/pull/3211#discussion_r89034578","pull_request_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211","_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments/89034578"},"html":{"href":"https://github.com/Azure/azure-powershell/pull/3211#discussion_r89034578"},"pull_request":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211"}}},"pull_request":{"url":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211","id":94446622,"html_url":"https://github.com/Azure/azure-powershell/pull/3211","diff_url":"https://github.com/Azure/azure-powershell/pull/3211.diff","patch_url":"https://github.com/Azure/azure-powershell/pull/3211.patch","issue_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3211","number":3211,"state":"open","locked":false,"title":"Repo tasks add spn","user":{"login":"shahabhijeet","id":20732208,"avatar_url":"https://avatars.githubusercontent.com/u/20732208?v=3","gravatar_id":"","url":"https://api.github.com/users/shahabhijeet","html_url":"https://github.com/shahabhijeet","followers_url":"https://api.github.com/users/shahabhijeet/followers","following_url":"https://api.github.com/users/shahabhijeet/following{/other_user}","gists_url":"https://api.github.com/users/shahabhijeet/gists{/gist_id}","starred_url":"https://api.github.com/users/shahabhijeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahabhijeet/subscriptions","organizations_url":"https://api.github.com/users/shahabhijeet/orgs","repos_url":"https://api.github.com/users/shahabhijeet/repos","events_url":"https://api.github.com/users/shahabhijeet/events{/privacy}","received_events_url":"https://api.github.com/users/shahabhijeet/received_events","type":"User","site_admin":false},"body":"Added cmdlet to create Service Principal.\r\nRefactored Repo-Tasks to include multiple modular modules (e.g. Build-Tasks, TestFx-Tasks)","created_at":"2016-11-18T22:15:14Z","updated_at":"2016-11-22T02:50:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"831c806dbe7ed5365b5f6c49667dc2cea2f0d9e7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211/commits","review_comments_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211/comments","review_comment_url":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/issues/3211/comments","statuses_url":"https://api.github.com/repos/Azure/azure-powershell/statuses/ec3fb1395e98b684dbf2a295cfb73ba8f4beec23","head":{"label":"shahabhijeet:repoTasks-addSpn","ref":"repoTasks-addSpn","sha":"ec3fb1395e98b684dbf2a295cfb73ba8f4beec23","user":{"login":"shahabhijeet","id":20732208,"avatar_url":"https://avatars.githubusercontent.com/u/20732208?v=3","gravatar_id":"","url":"https://api.github.com/users/shahabhijeet","html_url":"https://github.com/shahabhijeet","followers_url":"https://api.github.com/users/shahabhijeet/followers","following_url":"https://api.github.com/users/shahabhijeet/following{/other_user}","gists_url":"https://api.github.com/users/shahabhijeet/gists{/gist_id}","starred_url":"https://api.github.com/users/shahabhijeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahabhijeet/subscriptions","organizations_url":"https://api.github.com/users/shahabhijeet/orgs","repos_url":"https://api.github.com/users/shahabhijeet/repos","events_url":"https://api.github.com/users/shahabhijeet/events{/privacy}","received_events_url":"https://api.github.com/users/shahabhijeet/received_events","type":"User","site_admin":false},"repo":{"id":71402578,"name":"azure-powershell","full_name":"shahabhijeet/azure-powershell","owner":{"login":"shahabhijeet","id":20732208,"avatar_url":"https://avatars.githubusercontent.com/u/20732208?v=3","gravatar_id":"","url":"https://api.github.com/users/shahabhijeet","html_url":"https://github.com/shahabhijeet","followers_url":"https://api.github.com/users/shahabhijeet/followers","following_url":"https://api.github.com/users/shahabhijeet/following{/other_user}","gists_url":"https://api.github.com/users/shahabhijeet/gists{/gist_id}","starred_url":"https://api.github.com/users/shahabhijeet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shahabhijeet/subscriptions","organizations_url":"https://api.github.com/users/shahabhijeet/orgs","repos_url":"https://api.github.com/users/shahabhijeet/repos","events_url":"https://api.github.com/users/shahabhijeet/events{/privacy}","received_events_url":"https://api.github.com/users/shahabhijeet/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shahabhijeet/azure-powershell","description":"Microsoft Azure PowerShell","fork":true,"url":"https://api.github.com/repos/shahabhijeet/azure-powershell","forks_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/forks","keys_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/teams","hooks_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/hooks","issue_events_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/events","assignees_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/tags","blobs_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/languages","stargazers_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/stargazers","contributors_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/contributors","subscribers_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/subscribers","subscription_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/subscription","commits_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/merges","archive_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/downloads","issues_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/labels{/name}","releases_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/releases{/id}","deployments_url":"https://api.github.com/repos/shahabhijeet/azure-powershell/deployments","created_at":"2016-10-19T21:55:09Z","updated_at":"2016-10-19T21:55:37Z","pushed_at":"2016-11-18T22:11:23Z","git_url":"git://github.com/shahabhijeet/azure-powershell.git","ssh_url":"git@github.com:shahabhijeet/azure-powershell.git","clone_url":"https://github.com/shahabhijeet/azure-powershell.git","svn_url":"https://github.com/shahabhijeet/azure-powershell","homepage":null,"size":221504,"stargazers_count":0,"watchers_count":0,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"dev"}},"base":{"label":"Azure:dev","ref":"dev","sha":"38ab4636b79002371d4b280a4f3dde8a573345d3","user":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"repo":{"id":23891194,"name":"azure-powershell","full_name":"Azure/azure-powershell","owner":{"login":"Azure","id":6844498,"avatar_url":"https://avatars.githubusercontent.com/u/6844498?v=3","gravatar_id":"","url":"https://api.github.com/users/Azure","html_url":"https://github.com/Azure","followers_url":"https://api.github.com/users/Azure/followers","following_url":"https://api.github.com/users/Azure/following{/other_user}","gists_url":"https://api.github.com/users/Azure/gists{/gist_id}","starred_url":"https://api.github.com/users/Azure/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Azure/subscriptions","organizations_url":"https://api.github.com/users/Azure/orgs","repos_url":"https://api.github.com/users/Azure/repos","events_url":"https://api.github.com/users/Azure/events{/privacy}","received_events_url":"https://api.github.com/users/Azure/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Azure/azure-powershell","description":"Microsoft Azure PowerShell","fork":false,"url":"https://api.github.com/repos/Azure/azure-powershell","forks_url":"https://api.github.com/repos/Azure/azure-powershell/forks","keys_url":"https://api.github.com/repos/Azure/azure-powershell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Azure/azure-powershell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Azure/azure-powershell/teams","hooks_url":"https://api.github.com/repos/Azure/azure-powershell/hooks","issue_events_url":"https://api.github.com/repos/Azure/azure-powershell/issues/events{/number}","events_url":"https://api.github.com/repos/Azure/azure-powershell/events","assignees_url":"https://api.github.com/repos/Azure/azure-powershell/assignees{/user}","branches_url":"https://api.github.com/repos/Azure/azure-powershell/branches{/branch}","tags_url":"https://api.github.com/repos/Azure/azure-powershell/tags","blobs_url":"https://api.github.com/repos/Azure/azure-powershell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Azure/azure-powershell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Azure/azure-powershell/git/refs{/sha}","trees_url":"https://api.github.com/repos/Azure/azure-powershell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Azure/azure-powershell/statuses/{sha}","languages_url":"https://api.github.com/repos/Azure/azure-powershell/languages","stargazers_url":"https://api.github.com/repos/Azure/azure-powershell/stargazers","contributors_url":"https://api.github.com/repos/Azure/azure-powershell/contributors","subscribers_url":"https://api.github.com/repos/Azure/azure-powershell/subscribers","subscription_url":"https://api.github.com/repos/Azure/azure-powershell/subscription","commits_url":"https://api.github.com/repos/Azure/azure-powershell/commits{/sha}","git_commits_url":"https://api.github.com/repos/Azure/azure-powershell/git/commits{/sha}","comments_url":"https://api.github.com/repos/Azure/azure-powershell/comments{/number}","issue_comment_url":"https://api.github.com/repos/Azure/azure-powershell/issues/comments{/number}","contents_url":"https://api.github.com/repos/Azure/azure-powershell/contents/{+path}","compare_url":"https://api.github.com/repos/Azure/azure-powershell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Azure/azure-powershell/merges","archive_url":"https://api.github.com/repos/Azure/azure-powershell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Azure/azure-powershell/downloads","issues_url":"https://api.github.com/repos/Azure/azure-powershell/issues{/number}","pulls_url":"https://api.github.com/repos/Azure/azure-powershell/pulls{/number}","milestones_url":"https://api.github.com/repos/Azure/azure-powershell/milestones{/number}","notifications_url":"https://api.github.com/repos/Azure/azure-powershell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Azure/azure-powershell/labels{/name}","releases_url":"https://api.github.com/repos/Azure/azure-powershell/releases{/id}","deployments_url":"https://api.github.com/repos/Azure/azure-powershell/deployments","created_at":"2014-09-10T20:35:18Z","updated_at":"2016-11-18T17:19:34Z","pushed_at":"2016-11-22T02:41:10Z","git_url":"git://github.com/Azure/azure-powershell.git","ssh_url":"git@github.com:Azure/azure-powershell.git","clone_url":"https://github.com/Azure/azure-powershell.git","svn_url":"https://github.com/Azure/azure-powershell","homepage":null,"size":332236,"stargazers_count":589,"watchers_count":589,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":555,"mirror_url":null,"open_issues_count":484,"forks":555,"open_issues":484,"watchers":589,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211"},"html":{"href":"https://github.com/Azure/azure-powershell/pull/3211"},"issue":{"href":"https://api.github.com/repos/Azure/azure-powershell/issues/3211"},"comments":{"href":"https://api.github.com/repos/Azure/azure-powershell/issues/3211/comments"},"review_comments":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211/comments"},"review_comment":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Azure/azure-powershell/pulls/3211/commits"},"statuses":{"href":"https://api.github.com/repos/Azure/azure-powershell/statuses/ec3fb1395e98b684dbf2a295cfb73ba8f4beec23"}}}}
{"actor":{"display_login":"markcowl"}}