{"action":"opened","number":4687,"pull_request":{"url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687","id":233779505,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMzNzc5NTA1","html_url":"https://github.com/sqlcollaborative/dbatools/pull/4687","diff_url":"https://github.com/sqlcollaborative/dbatools/pull/4687.diff","patch_url":"https://github.com/sqlcollaborative/dbatools/pull/4687.patch","issue_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/4687","number":4687,"state":"open","locked":false,"title":"New function - Update-DbaInstance","user":{"login":"nvarscar","id":30303784,"node_id":"MDQ6VXNlcjMwMzAzNzg0","avatar_url":"https://avatars3.githubusercontent.com/u/30303784?v=4","gravatar_id":"","url":"https://api.github.com/users/nvarscar","html_url":"https://github.com/nvarscar","followers_url":"https://api.github.com/users/nvarscar/followers","following_url":"https://api.github.com/users/nvarscar/following{/other_user}","gists_url":"https://api.github.com/users/nvarscar/gists{/gist_id}","starred_url":"https://api.github.com/users/nvarscar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvarscar/subscriptions","organizations_url":"https://api.github.com/users/nvarscar/orgs","repos_url":"https://api.github.com/users/nvarscar/repos","events_url":"https://api.github.com/users/nvarscar/events{/privacy}","received_events_url":"https://api.github.com/users/nvarscar/received_events","type":"User","site_admin":false},"body":"Wish it could be smaller, but issues kept piling up until the very end, so bear with me 😇 \r\n## Type of Change\r\n<!-- What type of change does your code introduce -->\r\n - [ ] Bug fix (non-breaking change, fixes #<enter issue number>)\r\n - [x] New feature (non-breaking change, adds functionality)\r\n - [ ] Breaking change (effects multiple commands or functionality)\r\n - [x] Ran manual Pester test and has passed (`.\\tests\\manual.pester.ps1)\r\n - [x] Adding code coverage to existing functionality\r\n - [x] Pester test is included\r\n - [ ] Nunit test is included\r\n - [ ] Documentation\r\n - [ ] Build system\r\n \r\n<!-- Below this line you can erase anything that is not applicable -->\r\n### Purpose\r\nSQL Server patching functionality, including remote patching, multiple versions at once, CredSSP support and so on.\r\n\r\n### Approach\r\nIn short - I just kept throwing code at it until it gave up.\r\n\r\nAs discussed, I took [PsSqlUpdater](https://github.com/adbertram/PSSqlUpdater) from Adam Bertram as a reference and the core of it is in the PR. However, it was transformed to a point where I can no longer call it an adoption - there's almost no old code left, except for a few functions that work with remote registry (they are still huge though). All the functions were rewritten to support dbatools flow and were fully integrated with our build system (to a point where I had to add functionality to our build reference stuff). \r\n\r\nSo, there is one main command - **Update-DbaInstance** that controls the overall flow and handles multiple installations.\r\nThere's **Install-SqlServerUpdate** - which actually handles the installation logic and calls all the checks and whistles.\r\nThere's also **Invoke-Program**, which takes care of remote execution through a protocol that allows for passing credentials, which are required for properly running SQLServer setup/patching. Those protocols are:\r\n* CredSSP (there's Initialize-CredSSP that tries to configure both client and server to work together if possible)\r\n* Default with PSSessionConfiguration lifehack (suggested by @niphlod), which creates a remote PSSession configuration with RunAsCredential option. This is a little less secure than CredSSP, but it's the only alternative around, it seems. I leave it up to reviewers to decide if it's secure enough for us. It serves as a fallback after CredSSP has failed, so users might end up never using it if CredSSP works as intended in their environment.\r\n\r\n**Get-DbaBuildReference** was augmented with a couple more ParameterSets, as well as it now returns a few more properties, all of which are used by this new set of functions to ascertain current and target SQL Server builds and return proper KB names.\r\n\r\n**Get-SqlInstanceComponent** was copied almost from PsSqlUpdater as is (with a few additions on how to figure current SQL Version), and is a slight concern since it uses remote registry features that completely ignore -Credential parameters and act on behalf of current user. I would love to address it later, but it's already too big of a change, so I would rather do it during next iteration once all this stuff was reviewed and all the suggestions implemented.\r\n\r\n**Invoke-Command2** now supports -Authentication, -InputObject and remote PSSession configurations. Had to put Authentication type in the session name to avoid re-using a wrong session when protocols are switching, but I don't see any other ways of doing it except for changing the C# code, which I'm not ready to do just yet.\r\n\r\nNew PSSession configurations require remote WinRM service to be restarted (through... WinRM, hehe), which led to creating **Restart-WinRMService** function, which restarts the service and waits for the protocol to be brought back up.\r\n\r\nOther stuff deserves less attention, but it's still sitting there - wrappers, code reuse stuff (some of them could actually be internal functions inside internal functions, but most of them might prove useful in other scenarios, which is why I isolated them into their own files.\r\n\r\n### Commands to test\r\nUgh, there's only one, really: Update-DbaInstance. Pester tests are 100% UnitTests, without any remoting tests in place (for obvious reasons). I made this stuff work in my environment, but I'm completely unaware how it will work in your environment specifically, which is why .. please do test this stuff!\r\n\r\n### Screenshots\r\nUpgrading to latest version\r\n![image](https://user-images.githubusercontent.com/30303784/49058960-16074e00-f1cc-11e8-8517-d3c357b6732e.png)\r\n\r\nNo upgrade found - already at latest\r\n![image](https://user-images.githubusercontent.com/30303784/49058980-2fa89580-f1cc-11e8-9aee-155b87564773.png)\r\n\r\nInstalling specific patch version and not finding it\r\n![image](https://user-images.githubusercontent.com/30303784/49059238-8367ae80-f1cd-11e8-918d-cba04d143c5d.png)\r\n\r\n### Learning\r\nCredSSP had me crying at times\r\nWinRM is a **** and de-serialization sucks\r\nParallel execution will come later - definitely after initial release\r\n\r\n\r\n","created_at":"2018-11-27T04:51:00Z","updated_at":"2018-11-27T04:51:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687/commits","review_comments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687/comments","review_comment_url":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/4687/comments","statuses_url":"https://api.github.com/repos/sqlcollaborative/dbatools/statuses/99945c67dd2e17e882b87f274e204aa9c010b473","head":{"label":"nvarscar:update-sqlinstance","ref":"update-sqlinstance","sha":"99945c67dd2e17e882b87f274e204aa9c010b473","user":{"login":"nvarscar","id":30303784,"node_id":"MDQ6VXNlcjMwMzAzNzg0","avatar_url":"https://avatars3.githubusercontent.com/u/30303784?v=4","gravatar_id":"","url":"https://api.github.com/users/nvarscar","html_url":"https://github.com/nvarscar","followers_url":"https://api.github.com/users/nvarscar/followers","following_url":"https://api.github.com/users/nvarscar/following{/other_user}","gists_url":"https://api.github.com/users/nvarscar/gists{/gist_id}","starred_url":"https://api.github.com/users/nvarscar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvarscar/subscriptions","organizations_url":"https://api.github.com/users/nvarscar/orgs","repos_url":"https://api.github.com/users/nvarscar/repos","events_url":"https://api.github.com/users/nvarscar/events{/privacy}","received_events_url":"https://api.github.com/users/nvarscar/received_events","type":"User","site_admin":false},"repo":{"id":104483669,"node_id":"MDEwOlJlcG9zaXRvcnkxMDQ0ODM2Njk=","name":"dbatools-nvarscar","full_name":"nvarscar/dbatools-nvarscar","private":false,"owner":{"login":"nvarscar","id":30303784,"node_id":"MDQ6VXNlcjMwMzAzNzg0","avatar_url":"https://avatars3.githubusercontent.com/u/30303784?v=4","gravatar_id":"","url":"https://api.github.com/users/nvarscar","html_url":"https://github.com/nvarscar","followers_url":"https://api.github.com/users/nvarscar/followers","following_url":"https://api.github.com/users/nvarscar/following{/other_user}","gists_url":"https://api.github.com/users/nvarscar/gists{/gist_id}","starred_url":"https://api.github.com/users/nvarscar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvarscar/subscriptions","organizations_url":"https://api.github.com/users/nvarscar/orgs","repos_url":"https://api.github.com/users/nvarscar/repos","events_url":"https://api.github.com/users/nvarscar/events{/privacy}","received_events_url":"https://api.github.com/users/nvarscar/received_events","type":"User","site_admin":false},"html_url":"https://github.com/nvarscar/dbatools-nvarscar","description":"PowerShell module to help SQL Server Pros be more productive","fork":true,"url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar","forks_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/forks","keys_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/teams","hooks_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/hooks","issue_events_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/issues/events{/number}","events_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/events","assignees_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/assignees{/user}","branches_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/branches{/branch}","tags_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/tags","blobs_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/git/refs{/sha}","trees_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/statuses/{sha}","languages_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/languages","stargazers_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/stargazers","contributors_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/contributors","subscribers_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/subscribers","subscription_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/subscription","commits_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/commits{/sha}","git_commits_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/git/commits{/sha}","comments_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/comments{/number}","issue_comment_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/issues/comments{/number}","contents_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/contents/{+path}","compare_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/merges","archive_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/downloads","issues_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/issues{/number}","pulls_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/pulls{/number}","milestones_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/milestones{/number}","notifications_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/labels{/name}","releases_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/releases{/id}","deployments_url":"https://api.github.com/repos/nvarscar/dbatools-nvarscar/deployments","created_at":"2017-09-22T14:27:50Z","updated_at":"2018-03-08T16:50:37Z","pushed_at":"2018-11-27T04:50:49Z","git_url":"git://github.com/nvarscar/dbatools-nvarscar.git","ssh_url":"git@github.com:nvarscar/dbatools-nvarscar.git","clone_url":"https://github.com/nvarscar/dbatools-nvarscar.git","svn_url":"https://github.com/nvarscar/dbatools-nvarscar","homepage":"https://dbatools.io","size":97342,"stargazers_count":1,"watchers_count":1,"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":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"sqlcollaborative:development","ref":"development","sha":"a1acd6128a385d566e3e9216f6e8864a7f12a9b2","user":{"login":"sqlcollaborative","id":22203347,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMjAzMzQ3","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,"node_id":"MDEwOlJlcG9zaXRvcnkzMDIxNTIyNg==","name":"dbatools","full_name":"sqlcollaborative/dbatools","private":false,"owner":{"login":"sqlcollaborative","id":22203347,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIyMjAzMzQ3","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},"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-11-27T00:04:48Z","pushed_at":"2018-11-27T00:04:48Z","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":103212,"stargazers_count":716,"watchers_count":716,"language":"PowerShell","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":378,"mirror_url":null,"archived":false,"open_issues_count":163,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":378,"open_issues":163,"watchers":716,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687"},"html":{"href":"https://github.com/sqlcollaborative/dbatools/pull/4687"},"issue":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/4687"},"comments":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/issues/4687/comments"},"review_comments":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687/comments"},"review_comment":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/pulls/4687/commits"},"statuses":{"href":"https://api.github.com/repos/sqlcollaborative/dbatools/statuses/99945c67dd2e17e882b87f274e204aa9c010b473"}},"author_association":"CONTRIBUTOR","merged":false,"mergeable":null,"rebaseable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"maintainer_can_modify":true,"commits":19,"additions":1981,"deletions":25,"changed_files":16}}
{"actor":{"display_login":"nvarscar"}}