{"action":"created","comment":{"url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments/191137194","pull_request_review_id":123653016,"id":191137194,"diff_hunk":"@@ -109,26 +113,93 @@ function Copy-DbaResourceGovernor {\n             Notes             = $null\n             DateTime          = [DbaDateTime](Get-Date)\n         }\n+        \n+        $copyResourceGovClassifierFunc = [pscustomobject]@{\n+            SourceServer      = $sourceServer.Name\n+            DestinationServer = $destServer.Name\n+            Type              = \"Resource Governor Settings\"\n+            Name              = \"Classifier Function\"\n+            Status            = $null\n+            Notes             = $null\n+            DateTime          = [DbaDateTime](Get-Date)\n+        }\n \n         if ($Pscmdlet.ShouldProcess($destination, \"Updating Resource Governor settings\")) {\n             if ($destServer.Edition -notmatch 'Enterprise' -and $destServer.Edition -notmatch 'Datacenter' -and $destServer.Edition -notmatch 'Developer') {\n                 Write-Message -Level Verbose -Message \"The resource governor is not available in this edition of SQL Server. You can manipulate resource governor metadata but you will not be able to apply resource governor configuration. Only Enterprise edition of SQL Server supports resource governor.\"\n             }\n             else {\n                 try {\n-                    $sql = $sourceServer.ResourceGovernor.Script() | Out-String\n-                    Write-Message -Level Debug -Message $sql\n-                    Write-Message -Level Verbose -Message \"Updating Resource Governor settings.\"\n-                    $destServer.Query($sql)\n+                    Write-Message -Level Verbose -Message \"Managing classifier function.\"\n+                    if (!$sourceClassifierFunction) {\n+                        $copyResourceGovClassifierFunc.Status = \"Skipped\"\n+                        $copyResourceGovClassifierFunc.Notes = $null\n+                        $copyResourceGovClassifierFunc | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject\n+                    }\n+                    else {\n+                        $fullyQualifiedFunctionName = $sourceClassifierFunction.Schema+\".\"+$sourceClassifierFunction.Name\n+                                  \n+                        if (!$destClassifierFunction) {\n+                            $destFunction = $destServer.Databases[\"master\"].UserDefinedFunctions[$sourceClassifierFunction.Name]\n+\n+                            if ($destFunction) {\n+                                Write-Message -Level Verbose -Message \"Dropping the function with the source classifier function name.\"\n+                                $destFunction.Drop()\n+                            }\n \n-                    $copyResourceGovSetting.Status = \"Successful\"\n-                    $copyResourceGovSetting | Select-DefaultView -Property DateTime, SourceServer, DestinationServer, Name, Type, Status, Notes -TypeName MigrationObject\n+                            Write-Message -Level Verbose -Message \"Creating function.\"\n+                            $destServer.Query($sourceClassifierFunction.Script())\n+                            \n+                            $sql = \"ALTER RESOURCE GOVERNOR WITH (CLASSIFIER_FUNCTION = $fullyQualifiedFunctionName);\"\n+                            $sql\n+                            Write-Message -Level Debug -Message $sql\n+                            Write-Message -Level Verbose -Message \"Mapping Resource Governor classifier function.\"\n+                            $destServer.Query($sql)","path":"functions/Copy-DbaResourceGovernor.ps1","position":72,"original_position":72,"commit_id":"da249e98d100a2886d31b10c08ed51fd16b810e7","original_commit_id":"da249e98d100a2886d31b10c08ed51fd16b810e7","user":{"login":"suxstellino","id":2568107,"avatar_url":"https://avatars1.githubusercontent.com/u/2568107?v=4","gravatar_id":"","url":"https://api.github.com/users/suxstellino","html_url":"https://github.com/suxstellino","followers_url":"https://api.github.com/users/suxstellino/followers","following_url":"https://api.github.com/users/suxstellino/following{/other_user}","gists_url":"https://api.github.com/users/suxstellino/gists{/gist_id}","starred_url":"https://api.github.com/users/suxstellino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suxstellino/subscriptions","organizations_url":"https://api.github.com/users/suxstellino/orgs","repos_url":"https://api.github.com/users/suxstellino/repos","events_url":"https://api.github.com/users/suxstellino/events{/privacy}","received_events_url":"https://api.github.com/users/suxstellino/received_events","type":"User","site_admin":false},"body":"so you're suggesting me to indent the try/catch inside the outer one? I've copied the previous version which did a single block. Would you change fragmenting the commands into different try catch blocks?\r\n","created_at":"2018-05-28T07:59:22Z","updated_at":"2018-05-28T07:59:22Z","html_url":"https://github.com/sqlcollaborative/dbatools/pull/3580#discussion_r191137194","pull_request_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments/191137194"},"html":{"href":"https://github.com/sqlcollaborative/dbatools/pull/3580#discussion_r191137194"},"pull_request":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580"}},"in_reply_to_id":190768117},"pull_request":{"url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580","id":185865241,"html_url":"https://github.com/sqlcollaborative/dbatools/pull/3580","diff_url":"https://github.com/sqlcollaborative/dbatools/pull/3580.diff","patch_url":"https://github.com/sqlcollaborative/dbatools/pull/3580.patch","issue_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/3580","number":3580,"state":"open","locked":false,"title":"New Command - Get-DbaResourceGovernorClassifierFunction","user":{"login":"suxstellino","id":2568107,"avatar_url":"https://avatars1.githubusercontent.com/u/2568107?v=4","gravatar_id":"","url":"https://api.github.com/users/suxstellino","html_url":"https://github.com/suxstellino","followers_url":"https://api.github.com/users/suxstellino/followers","following_url":"https://api.github.com/users/suxstellino/following{/other_user}","gists_url":"https://api.github.com/users/suxstellino/gists{/gist_id}","starred_url":"https://api.github.com/users/suxstellino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suxstellino/subscriptions","organizations_url":"https://api.github.com/users/suxstellino/orgs","repos_url":"https://api.github.com/users/suxstellino/repos","events_url":"https://api.github.com/users/suxstellino/events{/privacy}","received_events_url":"https://api.github.com/users/suxstellino/received_events","type":"User","site_admin":false},"body":"## Type of Change\r\n<!-- What type of change does your code introduce -->\r\n - [ ] Bug fix (non-breaking change, fixes #)\r\n - [x] New feature (`Get-DbaResourceGovernorClassifierFunction` #3548)\r\n - [x] Breaking change (on `Copy-DbaResourceGovernor` #3548)\r\n - [ ] Ran manual Pester test and has passed (`.\\tests\\manual.pester.ps1)\r\n - [ ] Adding code coverage to existing functionality\r\n - [ ] Pester test is included\r\n - [ ] Nunit test is included\r\n - [x] Documentation\r\n - [ ] Build system\r\n \r\n### Purpose\r\nManaging the status of the resource governor (ignored before this change) and also the optional classifier function related to the resource governor itself. In order to get the classifier function, a new cmdlet has been added (`Get-DbaResourceGovernorClassifierFunction`) as described on the issue #3548.\r\n\r\n### Approach\r\n - Added a check of the status at the end of `Copy-DbaResourceGovernor` cmdlet \r\n - Added a new command `Get-DbaResourceGovernorClassifierFunction`\r\n - Added the logic for managing the classifier function when updating and reconfiguring resource governor\r\n\r\n### Commands to test\r\nSee help. \r\nAbout unit tests, no implementation has been made as described in issue #3548.\r\n","created_at":"2018-05-03T23:43:44Z","updated_at":"2018-05-28T07:59:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f15a11a2692a588bc9abdb0e55872cdaea235b2c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580/commits","review_comments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580/comments","review_comment_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/3580/comments","statuses_url":"https://api.github.com/repos/sqlcollaborative/dbatools/statuses/da249e98d100a2886d31b10c08ed51fd16b810e7","head":{"label":"suxstellino:development","ref":"development","sha":"da249e98d100a2886d31b10c08ed51fd16b810e7","user":{"login":"suxstellino","id":2568107,"avatar_url":"https://avatars1.githubusercontent.com/u/2568107?v=4","gravatar_id":"","url":"https://api.github.com/users/suxstellino","html_url":"https://github.com/suxstellino","followers_url":"https://api.github.com/users/suxstellino/followers","following_url":"https://api.github.com/users/suxstellino/following{/other_user}","gists_url":"https://api.github.com/users/suxstellino/gists{/gist_id}","starred_url":"https://api.github.com/users/suxstellino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suxstellino/subscriptions","organizations_url":"https://api.github.com/users/suxstellino/orgs","repos_url":"https://api.github.com/users/suxstellino/repos","events_url":"https://api.github.com/users/suxstellino/events{/privacy}","received_events_url":"https://api.github.com/users/suxstellino/received_events","type":"User","site_admin":false},"repo":{"id":129092595,"name":"dbatools","full_name":"suxstellino/dbatools","owner":{"login":"suxstellino","id":2568107,"avatar_url":"https://avatars1.githubusercontent.com/u/2568107?v=4","gravatar_id":"","url":"https://api.github.com/users/suxstellino","html_url":"https://github.com/suxstellino","followers_url":"https://api.github.com/users/suxstellino/followers","following_url":"https://api.github.com/users/suxstellino/following{/other_user}","gists_url":"https://api.github.com/users/suxstellino/gists{/gist_id}","starred_url":"https://api.github.com/users/suxstellino/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suxstellino/subscriptions","organizations_url":"https://api.github.com/users/suxstellino/orgs","repos_url":"https://api.github.com/users/suxstellino/repos","events_url":"https://api.github.com/users/suxstellino/events{/privacy}","received_events_url":"https://api.github.com/users/suxstellino/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/suxstellino/dbatools","description":"PowerShell module to help SQL Server Pros be more productive","fork":true,"url":"https://api.github.com/repos/suxstellino/dbatools","forks_url":"https://api.github.com/repos/suxstellino/dbatools/forks","keys_url":"https://api.github.com/repos/suxstellino/dbatools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/suxstellino/dbatools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/suxstellino/dbatools/teams","hooks_url":"https://api.github.com/repos/suxstellino/dbatools/hooks","issue_events_url":"https://api.github.com/repos/suxstellino/dbatools/issues/events{/number}","events_url":"https://api.github.com/repos/suxstellino/dbatools/events","assignees_url":"https://api.github.com/repos/suxstellino/dbatools/assignees{/user}","branches_url":"https://api.github.com/repos/suxstellino/dbatools/branches{/branch}","tags_url":"https://api.github.com/repos/suxstellino/dbatools/tags","blobs_url":"https://api.github.com/repos/suxstellino/dbatools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/suxstellino/dbatools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/suxstellino/dbatools/git/refs{/sha}","trees_url":"https://api.github.com/repos/suxstellino/dbatools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/suxstellino/dbatools/statuses/{sha}","languages_url":"https://api.github.com/repos/suxstellino/dbatools/languages","stargazers_url":"https://api.github.com/repos/suxstellino/dbatools/stargazers","contributors_url":"https://api.github.com/repos/suxstellino/dbatools/contributors","subscribers_url":"https://api.github.com/repos/suxstellino/dbatools/subscribers","subscription_url":"https://api.github.com/repos/suxstellino/dbatools/subscription","commits_url":"https://api.github.com/repos/suxstellino/dbatools/commits{/sha}","git_commits_url":"https://api.github.com/repos/suxstellino/dbatools/git/commits{/sha}","comments_url":"https://api.github.com/repos/suxstellino/dbatools/comments{/number}","issue_comment_url":"https://api.github.com/repos/suxstellino/dbatools/issues/comments{/number}","contents_url":"https://api.github.com/repos/suxstellino/dbatools/contents/{+path}","compare_url":"https://api.github.com/repos/suxstellino/dbatools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/suxstellino/dbatools/merges","archive_url":"https://api.github.com/repos/suxstellino/dbatools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/suxstellino/dbatools/downloads","issues_url":"https://api.github.com/repos/suxstellino/dbatools/issues{/number}","pulls_url":"https://api.github.com/repos/suxstellino/dbatools/pulls{/number}","milestones_url":"https://api.github.com/repos/suxstellino/dbatools/milestones{/number}","notifications_url":"https://api.github.com/repos/suxstellino/dbatools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/suxstellino/dbatools/labels{/name}","releases_url":"https://api.github.com/repos/suxstellino/dbatools/releases{/id}","deployments_url":"https://api.github.com/repos/suxstellino/dbatools/deployments","created_at":"2018-04-11T12:48:04Z","updated_at":"2018-05-10T14:30:50Z","pushed_at":"2018-05-10T14:30:48Z","git_url":"git://github.com/suxstellino/dbatools.git","ssh_url":"git@github.com:suxstellino/dbatools.git","clone_url":"https://github.com/suxstellino/dbatools.git","svn_url":"https://github.com/suxstellino/dbatools","homepage":"https://dbatools.io","size":84977,"stargazers_count":0,"watchers_count":0,"language":"PowerShell","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"development"}},"base":{"label":"sqlcollaborative:development","ref":"development","sha":"c345303ee2739b910f3f7bdb87e1382a3ec13d81","user":{"login":"sqlcollaborative","id":22203347,"avatar_url":"https://avatars3.githubusercontent.com/u/22203347?v=4","gravatar_id":"","url":"https://api.github.com/users/sqlcollaborative","html_url":"https://github.com/sqlcollaborative","followers_url":"https://api.github.com/users/sqlcollaborative/followers","following_url":"https://api.github.com/users/sqlcollaborative/following{/other_user}","gists_url":"https://api.github.com/users/sqlcollaborative/gists{/gist_id}","starred_url":"https://api.github.com/users/sqlcollaborative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sqlcollaborative/subscriptions","organizations_url":"https://api.github.com/users/sqlcollaborative/orgs","repos_url":"https://api.github.com/users/sqlcollaborative/repos","events_url":"https://api.github.com/users/sqlcollaborative/events{/privacy}","received_events_url":"https://api.github.com/users/sqlcollaborative/received_events","type":"Organization","site_admin":false},"repo":{"id":30215226,"name":"dbatools","full_name":"sqlcollaborative/dbatools","owner":{"login":"sqlcollaborative","id":22203347,"avatar_url":"https://avatars3.githubusercontent.com/u/22203347?v=4","gravatar_id":"","url":"https://api.github.com/users/sqlcollaborative","html_url":"https://github.com/sqlcollaborative","followers_url":"https://api.github.com/users/sqlcollaborative/followers","following_url":"https://api.github.com/users/sqlcollaborative/following{/other_user}","gists_url":"https://api.github.com/users/sqlcollaborative/gists{/gist_id}","starred_url":"https://api.github.com/users/sqlcollaborative/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sqlcollaborative/subscriptions","organizations_url":"https://api.github.com/users/sqlcollaborative/orgs","repos_url":"https://api.github.com/users/sqlcollaborative/repos","events_url":"https://api.github.com/users/sqlcollaborative/events{/privacy}","received_events_url":"https://api.github.com/users/sqlcollaborative/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sqlcollaborative/dbatools","description":"PowerShell module to help SQL Server Pros be more productive","fork":false,"url":"https://api.github.com/repos/sqlcollaborative/dbatools","forks_url":"https://api.github.com/repos/sqlcollaborative/dbatools/forks","keys_url":"https://api.github.com/repos/sqlcollaborative/dbatools/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sqlcollaborative/dbatools/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sqlcollaborative/dbatools/teams","hooks_url":"https://api.github.com/repos/sqlcollaborative/dbatools/hooks","issue_events_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/events{/number}","events_url":"https://api.github.com/repos/sqlcollaborative/dbatools/events","assignees_url":"https://api.github.com/repos/sqlcollaborative/dbatools/assignees{/user}","branches_url":"https://api.github.com/repos/sqlcollaborative/dbatools/branches{/branch}","tags_url":"https://api.github.com/repos/sqlcollaborative/dbatools/tags","blobs_url":"https://api.github.com/repos/sqlcollaborative/dbatools/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sqlcollaborative/dbatools/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sqlcollaborative/dbatools/git/refs{/sha}","trees_url":"https://api.github.com/repos/sqlcollaborative/dbatools/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sqlcollaborative/dbatools/statuses/{sha}","languages_url":"https://api.github.com/repos/sqlcollaborative/dbatools/languages","stargazers_url":"https://api.github.com/repos/sqlcollaborative/dbatools/stargazers","contributors_url":"https://api.github.com/repos/sqlcollaborative/dbatools/contributors","subscribers_url":"https://api.github.com/repos/sqlcollaborative/dbatools/subscribers","subscription_url":"https://api.github.com/repos/sqlcollaborative/dbatools/subscription","commits_url":"https://api.github.com/repos/sqlcollaborative/dbatools/commits{/sha}","git_commits_url":"https://api.github.com/repos/sqlcollaborative/dbatools/git/commits{/sha}","comments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/comments{/number}","issue_comment_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/comments{/number}","contents_url":"https://api.github.com/repos/sqlcollaborative/dbatools/contents/{+path}","compare_url":"https://api.github.com/repos/sqlcollaborative/dbatools/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sqlcollaborative/dbatools/merges","archive_url":"https://api.github.com/repos/sqlcollaborative/dbatools/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sqlcollaborative/dbatools/downloads","issues_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues{/number}","pulls_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls{/number}","milestones_url":"https://api.github.com/repos/sqlcollaborative/dbatools/milestones{/number}","notifications_url":"https://api.github.com/repos/sqlcollaborative/dbatools/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sqlcollaborative/dbatools/labels{/name}","releases_url":"https://api.github.com/repos/sqlcollaborative/dbatools/releases{/id}","deployments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/deployments","created_at":"2015-02-02T23:50:31Z","updated_at":"2018-05-28T05:47:09Z","pushed_at":"2018-05-25T23:24:25Z","git_url":"git://github.com/sqlcollaborative/dbatools.git","ssh_url":"git@github.com:sqlcollaborative/dbatools.git","clone_url":"https://github.com/sqlcollaborative/dbatools.git","svn_url":"https://github.com/sqlcollaborative/dbatools","homepage":"https://dbatools.io","size":85519,"stargazers_count":585,"watchers_count":585,"language":"PowerShell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":323,"mirror_url":null,"archived":false,"open_issues_count":308,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":323,"open_issues":308,"watchers":585,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580"},"html":{"href":"https://github.com/sqlcollaborative/dbatools/pull/3580"},"issue":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/3580"},"comments":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/3580/comments"},"review_comments":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580/comments"},"review_comment":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/3580/commits"},"statuses":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/statuses/da249e98d100a2886d31b10c08ed51fd16b810e7"}},"author_association":"NONE"}}
{"actor":{"display_login":"suxstellino"}}