-
Notifications
You must be signed in to change notification settings - Fork 12
/
Connect-DbaInstance.html
1591 lines (1563 loc) · 57 KB
/
Connect-DbaInstance.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>dbatools docs | Connect-DbaInstance</title>
<link rel="icon" href="https://dbatools.io/wp-content/uploads/2016/05/dbatools.png" sizes="32x32">
<link rel="icon" href="https://dbatools.io/wp-content/uploads/2016/05/dbatools.png" sizes="192x192">
<link rel="apple-touch-icon-precomposed" href="https://dbatools.io/wp-content/uploads/2016/05/dbatools.png">
<meta name="msapplication-TileImage" content="https://dbatools.io/wp-content/uploads/2016/05/dbatools.png">
<link title="Search" rel="search" type="application/opensearchdescription+xml" href="/opensearch.xml">
<meta name="keywords" content="dbatools, ,powershell,sql server,devops,json">
<meta name="subtitle" content="Docs for Connect-DbaInstance">
<meta property="og:type" content="article" />
<meta property="og:title" content="dbatools docs: Connect-DbaInstance" />
<meta property="og:url" content="https://docs.dbatools.io/Connect-DbaInstance.html" />
<meta property="og:description" content="dbatools docs for Connect-DbaInstance" />
<meta property="og:site_name" content="docs.dbatools.io" />
<meta property="og:locale" content="en_US" />
<meta name="twitter:text:title" content="dbatools docs: Connect-DbaInstance" />
<meta name="twitter:image" content="https://docs.dbatools.io/assets/thumbs/Connect-DbaInstance.png">
<meta name="twitter:card" content="summary_large_image">
<meta name=twitter:creator content="@psdbatools">
<meta name=twitter:title content="dbatools docs: Connect-DbaInstance">
<meta property="twitter:site" content="@psdbatools" />
<meta property="og:image" content="https://docs.dbatools.io/assets/thumbs/Connect-DbaInstance.png">
<link rel=canonical href="https://docs.dbatools.io/Connect-DbaInstance.html" />
<link rel=alternate type=application/json
href=https://raw.githubusercontent.com/dataplat/dbatools/master/bin/dbatools-index.json
title="dbatools documentation">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"
integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<link rel="stylesheet" type="text/css"
href="//cdnjs.cloudflare.com/ajax/libs/open-iconic/1.1.1/font/css/open-iconic-bootstrap.min.css">
<link rel="stylesheet" type="text/css"
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
<link rel="stylesheet" href="assets/css/layout.css">
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-80639740-2"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'UA-80639740-2');
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"
integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
crossorigin="anonymous"></script>
<script src="//cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/list.js/1.5.0/list.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/autolinker/1.7.1/Autolinker.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jqcloud2@2.0.3/dist/jqcloud.min.js"
integrity="sha256-+krhsKJpvd3AZYVGHcwyCUGO01uNdGSTvqR7Apcy30E=" crossorigin="anonymous"></script>
<script type="text/javascript" language="javascript">
function register_dbatools_hljs(dbatoolscommands) {
hljs.registerLanguage("powershell", function (e) {
var t = {
b: "`[\\s\\S]",
r: 0
},
o = {
cN: "variable",
v: [{
b: /\$[\w\d][\w\d_:]*/
}]
},
r = {
cN: "literal",
b: /\$(null|true|false)\b/
},
n = {
cN: "string",
v: [{
b: /"/,
e: /"/
}, {
b: /@"/,
e: /^"@/
}],
c: [t, o, {
cN: "variable",
b: /\$[A-z]/,
e: /[^A-z]/
}]
},
a = {
cN: "string",
v: [{
b: /'/,
e: /'/
}, {
b: /@'/,
e: /^'@/
}]
},
i = {
cN: "doctag",
v: [{
b: /\.(synopsis|description|example|inputs|outputs|notes|link|component|role|functionality)/
}, {
b: /\.(parameter|forwardhelptargetname|forwardhelpcategory|remotehelprunspace|externalhelp)\s+\S+/
}]
},
s = e.inherit(e.C(null, null), {
v: [{
b: /#/,
e: /$/
}, {
b: /<#/,
e: /#>/
}],
c: [i]
});
return {
aliases: ["ps"],
l: /-?[A-z\.\-]+/,
cI: !0,
k: {
keyword: "if else foreach return function do while until elseif begin for trap data dynamicparam end break throw param continue finally in switch exit filter try process catch",
built_in: dbatoolscommands + " Add-Computer Add-Content Add-History Add-JobTrigger Add-Member Add-PSSnapin Add-Type Checkpoint-Computer Clear-Content Clear-EventLog Clear-History Clear-Host Clear-Item Clear-ItemProperty Clear-Variable Compare-Object Complete-Transaction Connect-PSSession Connect-WSMan Convert-Path ConvertFrom-Csv ConvertFrom-Json ConvertFrom-SecureString ConvertFrom-StringData ConvertTo-Csv ConvertTo-Html ConvertTo-Json ConvertTo-SecureString ConvertTo-Xml Copy-Item Copy-ItemProperty Debug-Process Disable-ComputerRestore Disable-JobTrigger Disable-PSBreakpoint Disable-PSRemoting Disable-PSSessionConfiguration Disable-WSManCredSSP Disconnect-PSSession Disconnect-WSMan Disable-ScheduledJob Enable-ComputerRestore Enable-JobTrigger Enable-PSBreakpoint Enable-PSRemoting Enable-PSSessionConfiguration Enable-ScheduledJob Enable-WSManCredSSP Enter-PSSession Exit-PSSession Export-Alias Export-Clixml Export-Console Export-Counter Export-Csv Export-FormatData Export-ModuleMember Export-PSSession ForEach-Object Format-Custom Format-List Format-Table Format-Wide Get-Acl Get-Alias Get-AuthenticodeSignature Get-ChildItem Get-Command Get-ComputerRestorePoint Get-Content Get-ControlPanelItem Get-Counter Get-Credential Get-Culture Get-Date Get-Event Get-EventLog Get-EventSubscriber Get-ExecutionPolicy Get-FormatData Get-Host Get-HotFix Get-Help Get-History Get-IseSnippet Get-Item Get-ItemProperty Get-Job Get-JobTrigger Get-Location Get-Member Get-Module Get-PfxCertificate Get-Process Get-PSBreakpoint Get-PSCallStack Get-PSDrive Get-PSProvider Get-PSSession Get-PSSessionConfiguration Get-PSSnapin Get-Random Get-ScheduledJob Get-ScheduledJobOption Get-Service Get-TraceSource Get-Transaction Get-TypeData Get-UICulture Get-Unique Get-Variable Get-Verb Get-WinEvent Get-WmiObject Get-WSManCredSSP Get-WSManInstance Group-Object Import-Alias Import-Clixml Import-Counter Import-Csv Import-IseSnippet Import-LocalizedData Import-PSSession Import-Module Invoke-AsWorkflow Invoke-Command Invoke-Expression Invoke-History Invoke-Item Invoke-RestMethod Invoke-WebRequest Invoke-WmiMethod Invoke-WSManAction Join-Path Limit-EventLog Measure-Command Measure-Object Move-Item Move-ItemProperty New-Alias New-Event New-EventLog New-IseSnippet New-Item New-ItemProperty New-JobTrigger New-Object New-Module New-ModuleManifest New-PSDrive New-PSSession New-PSSessionConfigurationFile New-PSSessionOption New-PSTransportOption New-PSWorkflowExecutionOption New-PSWorkflowSession New-ScheduledJobOption New-Service New-TimeSpan New-Variable New-WebServiceProxy New-WinEvent New-WSManInstance New-WSManSessionOption Out-Default Out-File Out-GridView Out-Host Out-Null Out-Printer Out-String Pop-Location Push-Location Read-Host Receive-Job Register-EngineEvent Register-ObjectEvent Register-PSSessionConfiguration Register-ScheduledJob Register-WmiEvent Remove-Computer Remove-Event Remove-EventLog Remove-Item Remove-ItemProperty Remove-Job Remove-JobTrigger Remove-Module Remove-PSBreakpoint Remove-PSDrive Remove-PSSession Remove-PSSnapin Remove-TypeData Remove-Variable Remove-WmiObject Remove-WSManInstance Rename-Computer Rename-Item Rename-ItemProperty Reset-ComputerMachinePassword Resolve-Path Restart-Computer Restart-Service Restore-Computer Resume-Job Resume-Service Save-Help Select-Object Select-String Select-Xml Send-MailMessage Set-Acl Set-Alias Set-AuthenticodeSignature Set-Content Set-Date Set-ExecutionPolicy Set-Item Set-ItemProperty Set-JobTrigger Set-Location Set-PSBreakpoint Set-PSDebug Set-PSSessionConfiguration Set-ScheduledJob Set-ScheduledJobOption Set-Service Set-StrictMode Set-TraceSource Set-Variable Set-WmiInstance Set-WSManInstance Set-WSManQuickConfig Show-Command Show-ControlPanelItem Show-EventLog Sort-Object Split-Path Start-Job Start-Process Start-Service Start-Sleep Start-Transaction Start-Transcript Stop-Computer Stop-Job Stop-Process Stop-Service Stop-Transcript Suspend-Job Suspend-Service Tee-Object Test-ComputerSecureChannel Test-Connection Test-ModuleManifest Test-Path Test-PSSessionConfigurationFile Trace-Command Unblock-File Undo-Transaction Unregister-Event Unregister-PSSessionConfiguration Unregister-ScheduledJob Update-FormatData Update-Help Update-List Update-TypeData Use-Transaction Wait-Event Wait-Job Wait-Process Where-Object Write-Debug Write-Error Write-EventLog Write-Host Write-Output Write-Progress Write-Verbose Write-Warning Add-MDTPersistentDrive Disable-MDTMonitorService Enable-MDTMonitorService Get-MDTDeploymentShareStatistics Get-MDTMonitorData Get-MDTOperatingSystemCatalog Get-MDTPersistentDrive Import-MDTApplication Import-MDTDriver Import-MDTOperatingSystem Import-MDTPackage Import-MDTTaskSequence New-MDTDatabase Remove-MDTMonitorData Remove-MDTPersistentDrive Restore-MDTPersistentDrive Set-MDTMonitorData Test-MDTDeploymentShare Test-MDTMonitorData Update-MDTDatabaseSchema Update-MDTDeploymentShare Update-MDTLinkedDS Update-MDTMedia Update-MDTMedia Add-VamtProductKey Export-VamtData Find-VamtManagedMachine Get-VamtConfirmationId Get-VamtProduct Get-VamtProductKey Import-VamtData Initialize-VamtData Install-VamtConfirmationId Install-VamtProductActivation Install-VamtProductKey Update-VamtProduct",
nomarkup: "-ne -eq -lt -gt -ge -le -not -like -notlike -match -notmatch -contains -notcontains -in -notin -replace"
},
c: [t, e.NM, n, a, r, o, s]
}
});
}
$(document).ready(function () {
function render_doc(doc_to_render, examples_mode) {
$("#rendered h5").each(function (i, el) {
if ($(el).text().startsWith('-')) {
$(el).addClass('param')
}
})
$('#rendered table').addClass('table table-sm table-hover')
if (examples_mode == 'new') {
$('#rendered code').addClass('powershell')
}
$('#rendered code').each(function (i, block) {
hljs.highlightBlock(block);
})
var authorcontent = $("td:contains('Author')").next('td').addClass('dbatools_author').text()
$("#rendered .dbatools_author").html(Autolinker.link(authorcontent, {
className: 'myLink',
mention: 'twitter'
})
)
$("#rendered h2#syntax").next().find('code').addClass('wrapped')
if (ClipboardJS.isSupported()) {
$("#rendered h5[id^='example-']").append('<div class="bd-clipboard"><button class="btn-clipboard" title="Copy to clipboard">Copy</button></div>')
new ClipboardJS('.btn-clipboard', {
text: function (trigger) {
var textlines = $(trigger).parent().parent().next('pre').find('code').text().split('\n')
var copied = []
_.forEach(textlines, function (row) {
copied.push(row.replace(/^PS C:\\> /, "").replace(/^>>/, ""))
})
return _.join(copied, '\n')
}
});
}
//not all code is a block
$("#rendered h3[id*='-parameters']").nextAll().find('code').addClass('hljs-inline')
$('#rendered #description').nextUntil('#rendered #syntax').find('code').addClass('hljs-inline')
}
$('#loader').removeClass('invisible')
var index_url = 'assets/dbatools-index.json'
var external_url = 'assets/external.json'
var values = [];
var options = {
valueNames: ['CommandName', 'Description', 'Alias', 'Examples', 'Params'],
item: '<a class="list-group-item" href="#"><span class="CommandName"></span></a>'
}
cmdlist = new List('cmdlist', options, values);
var indexhelp = ''
var allcmds = $.getJSON(index_url, function (data) {
indexhelp = data
cmdlist.add(data)
var dbacommands = []
var cloudlist = {}
_.forEach(data, function (el) {
dbacommands.push(el.CommandName)
if (_.isArray(el.Tags)) {
_.forEach(el.Tags, function (el) {
if (!_.has(cloudlist, el)) {
cloudlist[el] = 0
}
cloudlist[el] += 1
})
} else if (!_.isUndefined(el.Tags)){
if (!_.has(cloudlist, el.Tags)) {
cloudlist[el.Tags] = 0
}
cloudlist[el.Tags] += 1
}
})
var weightedVals = []
_.forEach(cloudlist, function (value, key) {
weightedVals.push({
text: key,
weight: value,
handlers: {
click: function () { $('#search-ft').val('tag:' + key).trigger('keyup') }
}
})
})
var pixelHeight = window.innerHeight * 0.65;
$('#canvas').css({ 'height': pixelHeight + 'px' });
$('#canvas').jQCloud(weightedVals, {
autoResize: true
});
register_dbatools_hljs(dbacommands.join(' '))
$(window).trigger('hashchange');
})
var options2 = {
valueNames: ['extName', { name: 'extHref', attr: 'href' }],
item: '<div><a class="list-group-item list-group-item-secondary extHref" href="#" _target="_blank"><span class="extName"></span></a></div>'
}
extlist = new List('extlist', options2, [])
$.getJSON(external_url, function (data) {
$('#dbatools_version').text('(v ' + data.version + ')')
_.forEach(data.external_links, function (el) {
extlist.add({ 'extName': el.name, 'extHref': el.href })
})
})
cmdlist.on('searchComplete', function (e) {
if (cmdlist.matchingItems.length === 0) {
var searchString = $('#search-ft').val().trim();
if (searchString.length > 0 && !searchString.startsWith("ft:")) {
if (searchString != "f" && searchString != "ft" && searchString != "ft:") {
$('#search-ft').val("ft:" + searchString)
}
}
}
})
$(document).on('mouseenter', '#cmdlist', function (e) {
$('#search-ft').blur();
})
cmdlist.on('updated', function() {
$('#cmdlist a').each(function(i, el) {
$(el).attr('href', $(el).find('span.CommandName').text())
})
})
$('#cmdlist').on('mouseenter', 'a', function (e) {
$(this).attr('href', $(this).find('span.CommandName').text());
/*
e.preventDefault();
window.location.href = $(this).find('span.CommandName').text()
---
window.location.hash = '#' + $(this).find('span.CommandName').text();
$('#cmdlist').find('a.active').removeClass('active')
$(this).addClass('active')
*/
})
$('#search-ft').bind('change keyup', function () {
var searchString = $(this).val();
if (searchString.trim() == "ft:" || searchString.trim() == "tag:") {
extlist.search();
}
else if (searchString.startsWith("ft:")) {
searchString = searchString.substring(3).trim();
if (cmdlist.filtered) {
cmdlist.filter();
}
cmdlist.search(searchString, ['CommandName', 'Alias', 'Description', 'Synopsis', 'Examples', 'Params']);
} else if (searchString.startsWith("tag:")) {
searchString = searchString.substring(4).trim();
if (cmdlist.searched) {
cmdlist.search();
}
cmdlist.filter(function (item) {
if (_.indexOf(item.values().Tags, searchString) !== -1) {
return true;
} else {
return false;
}
});
} else {
if (cmdlist.filtered) {
cmdlist.filter();
}
cmdlist.search(searchString, ['CommandName', 'Alias']);
}
extlist.search('$$$')
if (_.isEmpty(searchString)) {
extlist.search()
cmdlist.filter()
}
})
$('#clear-search').on('click', function () {
$('#search-ft').val('').trigger('keyup')
})
$(window).on('hashchange', function (e) {
var hash = window.location.hash.substr(1);
var pagename = window.location.pathname.split("/").filter(function (c) { return c.length; }).pop();
if (_.isUndefined(pagename)) {
pagename = ''
} else {
pagename = pagename.split('.')[0];
}
if (hash.length == 0) {
hash = pagename
}
if (hash.length > 0) {
//ends with /
if (_.endsWith(hash, '/')) {
window.location.hash = '#' + hash.slice(0, hash.length - 1)
$(window).trigger('hashchange');
return;
}
//exact match
var topublish = _.findIndex(indexhelp, { 'Name': hash })
if (topublish == -1) {
//lowercase match
var topublish = _.findIndex(indexhelp, function (el) { return _.toLower(el.Name) == _.toLower(hash) })
if (topublish == -1) {
//alias match
var topublish = _.findIndex(indexhelp, { 'Alias': hash })
if (topublish == -1) {
//lowercase alias match
var topublish = _.findIndex(indexhelp, function (el) { return _.toLower(el.Alias) == _.toLower(hash) })
}
if (topublish == -1) {
//multiple aliases, optionally lowercased
var topublish = _.findIndex(indexhelp, function (el) { return _.includes(_.toLower(el.Alias).split(','), _.toLower(hash)) })
}
}
if (topublish !== -1) {
//normalization of URI
window.location.hash = '#' + indexhelp[topublish].CommandName
$(window).trigger('hashchange')
return;
}
}
if (topublish == -1) {
$('#rendered').html(marked.parse('### 404 Function not found \n (while searching for ' + hash + '). Please visit dbatools.io/commands for an updated index of current commands.'));
} else {
var doc_to_render = indexhelp[topublish]
render_doc(doc_to_render, 'new')
$("body").data("doc_to_render", indexhelp[topublish])
if ($("#headscroll").offset().top > 150) {
$(window).scrollTo('#headscroll')
} else {
$(window).scrollTo(0, 800)
}
}
} else {
$('#loader').addClass('invisible')
}
})
$(window).scroll(function () {
if ($(this).scrollTop() > 50) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
})
$('#back-to-top').click(function () {
$(window).scrollTo(0, 800)
return false;
})
})
</script>
</head>
<body>
<nav class="navbar navbar-expand-md customnav">
<a href="https://docs.dbatools.io/" class="navbar-brand" rel="home" itemprop="url">
<img width="265" height="64" src="https://dbatools.io/wp-content/uploads/2018/09/dbatools-docs.png"
class="custom-logo" alt="dbatools" itemprop="logo" scale="0">
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="oi oi-menu"></span>
</button>
<div class="collapse navbar-collapse flex-grow-1 text-right" id="navbarCollapse">
<ul class="navbar-nav ml-auto flex-nowrap">
<li class="nav-item">
<a class="nav-link" style="color:#293E5D" href="https://dbatools.io/download/">⬇ download</a>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#293E5D" href="https://dbatools.io/commands/">🚀 commands</a>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#293E5D" href="https://dbatools.io/slack">🔍 find us</a>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#293E5D" href="https://dbatools.io/builds">🔢 build ref</a>
</li>
<li class="nav-item">
<a class="nav-link" style="color:#293E5D" href="https://dbatools.io/book">📘 dbatools book</a>
</li>
</ul>
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<hr />
</div>
</div>
<div class="row">
<div class="col-xl-3 col-lg-5 col-md-5 col-sm-12 bd-sidebar">
<div id="relcommands" class="">
<h3>
commands
<small id="dbatools_version" class="text-muted"></small>
</h3>
<p></p>
<div class="form-group row">
<div class="col-lg-12">
<div class="input-group">
<input type="text" class="form-control" id="search-ft"
placeholder="Search ("ft: term" enables fulltext)" autocomplete="off">
<div class="input-group-append">
<div class="input-group-text" id="clear-search">Clear</div>
</div>
</div>
</div>
</div>
<div id="extlist">
<div class="list list-group"></div>
</div>
<div id="cmdlist">
<div class="list list-group"></div>
</div>
</div>
</div>
<div class="col-xl-9 col-lg-7 col-md-7 col-sm-12 bd-content">
<div id="headscroll">
<a id="back-to-top" href="#" class="btn btn-primary btn-lg back-to-top" role="button"
title="Click to return on the top page">^</a>
</div>
<div id="rendered">
<h1 id="connect-dbainstance">Connect-DbaInstance</h1>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Author</strong></td>
<td>Chrissy LeMaire (@cl), netnerds.net</td>
</tr>
<tr>
<td><strong>Availability</strong></td>
<td>Windows, Linux, macOS</td>
</tr>
</tbody>
</table>
<p> </p>
<p><em>Aliases : cdi</em></p>
<p>Want to see the source code for this command? Check out <a href="https://github.com/dataplat/dbatools/blob/master/public/Connect-DbaInstance.ps1">Connect-DbaInstance</a> on GitHub.
<br>
Want to see the Bill Of Health for this command? Check out <a href="https://dataplat.github.io/boh#Connect-DbaInstance">Connect-DbaInstance</a>.</p>
<h2 id="synopsis">Synopsis</h2>
<p>Creates a robust, reusable SQL Server object.</p>
<h2 id="description">Description</h2>
<p>This command creates a robust, reusable sql server object.</p>
<p>It is robust because it initializes properties that do not cause enumeration by default. It also supports both Windows and SQL Server authentication methods, and detects which to use based upon the provided credentials.</p>
<p>By default, this command also sets the connection's ApplicationName property to "dbatools PowerShell module - dbatools.io - custom connection". If you're doing anything that requires profiling, you can look for this client name.</p>
<p>Alternatively, you can pass in whichever client name you'd like using the -ClientName parameter. There are a ton of other parameters for you to explore as well.</p>
<p>See <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx">https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx</a><br />
and <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx">https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx</a>,<br />
and <a href="https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx">https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx</a></p>
<p>To execute SQL commands, you can use $server.ConnectionContext.ExecuteReader($sql) or $server.Databases['master'].ExecuteNonQuery($sql)</p>
<h2 id="syntax">Syntax</h2>
<pre><code>Connect-DbaInstance
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String>]
[[-ApplicationIntent] <String>]
[-AzureUnsupported]
[[-BatchSeparator] <String>]
[[-ClientName] <String>]
[[-ConnectTimeout] <Int32>]
[-EncryptConnection]
[[-FailoverPartner] <String>]
[[-LockTimeout] <Int32>]
[[-MaxPoolSize] <Int32>]
[[-MinPoolSize] <Int32>]
[[-MinimumVersion] <Int32>]
[-MultipleActiveResultSets]
[-MultiSubnetFailover]
[[-NetworkProtocol] <String>]
[-NonPooledConnection]
[[-PacketSize] <Int32>]
[[-PooledConnectionLifetime] <Int32>]
[[-SqlExecutionModes] <String>]
[[-StatementTimeout] <Int32>]
[-TrustServerCertificate]
[[-WorkstationId] <String>]
[-AlwaysEncrypted]
[[-AppendConnectionString] <String>]
[-SqlConnectionOnly]
[[-AzureDomain] <String>]
[[-Tenant] <String>]
[[-AccessToken] <PSObject>]
[-DedicatedAdminConnection]
[-DisableException]
[<CommonParameters>]
</code></pre>
<p> </p>
<h2 id="examples">Examples</h2>
<p> </p>
<h5 id="example-1">Example: 1</h5>
<pre><code>PS C:\> Connect-DbaInstance -SqlInstance sql2014
</code></pre>
<p>Creates an SMO Server object that connects using Windows Authentication<br></p>
<h5 id="example-2">Example: 2</h5>
<pre><code>PS C:\> $wincred = Get-Credential ad\sqladmin
PS C:\> Connect-DbaInstance -SqlInstance sql2014 -SqlCredential $wincred
</code></pre>
<p>Creates an SMO Server object that connects using alternative Windows credentials<br></p>
<h5 id="example-3">Example: 3</h5>
<pre><code>PS C:\> $sqlcred = Get-Credential sqladmin
PS C:\> $server = Connect-DbaInstance -SqlInstance sql2014 -SqlCredential $sqlcred
</code></pre>
<p>Login to sql2014 as SQL login sqladmin.<br></p>
<h5 id="example-4">Example: 4</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance sql2014 -ClientName "my connection"
</code></pre>
<p>Creates an SMO Server object that connects using Windows Authentication and uses the client name "my connection".<br>
So when you open up profiler or use extended events, you can search for "my connection".<br></p>
<h5 id="example-5">Example: 5</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance sql2014 -AppendConnectionString "Packet Size=4096;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;User Instance=true;"
</code></pre>
<p>Creates an SMO Server object that connects to sql2014 using Windows Authentication, then it sets the packet size (this can also be done via -PacketSize) and other connection attributes.<br></p>
<h5 id="example-6">Example: 6</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance sql2014 -NetworkProtocol TcpIp -MultiSubnetFailover
</code></pre>
<p>Creates an SMO Server object that connects using Windows Authentication that uses TCP/IP and has MultiSubnetFailover enabled.<br></p>
<h5 id="example-7">Example: 7</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance sql2016 -ApplicationIntent ReadOnly
</code></pre>
<p>Connects with ReadOnly ApplicationIntent.<br></p>
<h5 id="example-8">Example: 8</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance myserver.database.windows.net -Database mydb -SqlCredential me@mydomain.onmicrosoft.com -DisableException
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>Logs into Azure SQL DB using AAD / Azure Active Directory, then performs a sample query.<br></p>
<h5 id="example-9">Example: 9</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance psdbatools.database.windows.net -Database dbatools -DisableException
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>Logs into Azure SQL DB using AAD Integrated Auth, then performs a sample query.<br></p>
<h5 id="example-10">Example: 10</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance "myserver.public.cust123.database.windows.net,3342" -Database mydb -SqlCredential me@mydomain.onmicrosoft.com -DisableException
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>Logs into Azure SQL Managed instance using AAD / Azure Active Directory, then performs a sample query.<br></p>
<h5 id="example-11">Example: 11</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance db.mycustomazure.com -Database mydb -AzureDomain mycustomazure.com -DisableException
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>In the event your AzureSqlDb is not on a database.windows.net domain, you can set a custom domain using the AzureDomain parameter.<br>
This tells Connect-DbaInstance to login to the database using the method that works best with Azure.<br></p>
<h5 id="example-12">Example: 12</h5>
<pre><code>PS C:\> $connstring = "Data Source=TCP:mydb.database.windows.net,1433;User ID=sqladmin;Password=adfasdf;Connect Timeout=30;"
PS C:\> $server = Connect-DbaInstance -ConnectionString $connstring
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>Logs into Azure using a preconstructed connstring, then performs a sample query.<br>
ConnectionString is an alias of SqlInstance, so you can use -SqlInstance $connstring as well.<br></p>
<h5 id="example-13">Example: 13</h5>
<pre><code>PS C:\> $cred = Get-Credential guid-app-id-here # appid for username, clientsecret for password
PS C:\> $server = Connect-DbaInstance -SqlInstance psdbatools.database.windows.net -Database abc -SqlCredential $cred -Tenant guidheremaybename
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>When connecting from a non-Azure workstation, logs into Azure using Universal with MFA Support with a username and password, then performs a sample query.<br>
Note that generating access tokens is not supported on Core, so when using Tenant on Core, we rewrite the connection string with Active Directory Service Principal authentication instead.<br></p>
<h5 id="example-14">Example: 14</h5>
<pre><code>PS C:\> $cred = Get-Credential guid-app-id-here # appid for username, clientsecret for password
PS C:\> Set-DbatoolsConfig -FullName azure.tenantid -Value 'guidheremaybename' -Passthru | Register-DbatoolsConfig
PS C:\> Set-DbatoolsConfig -FullName azure.appid -Value $cred.Username -Passthru | Register-DbatoolsConfig
PS C:\> Set-DbatoolsConfig -FullName azure.clientsecret -Value $cred.Password -Passthru | Register-DbatoolsConfig # requires securestring
PS C:\> Set-DbatoolsConfig -FullName sql.connection.database -Value abc -Passthru | Register-DbatoolsConfig
PS C:\> Connect-DbaInstance -SqlInstance psdbatools.database.windows.net
</code></pre>
<p>Permanently sets some app id config values. To set them temporarily (just for a session), remove -Passthru | Register-DbatoolsConfig<br>
When connecting from a non-Azure workstation or an Azure VM without .NET 4.7.2 and higher, logs into Azure using Universal with MFA Support, then performs a sample query.<br></p>
<h5 id="example-15">Example: 15</h5>
<pre><code>PS C:\> $azureCredential = Get-Credential -Message 'Azure Credential'
PS C:\> $azureAccount = Connect-AzAccount -Credential $azureCredential
PS C:\> $azureToken = Get-AzAccessToken -ResourceUrl https://database.windows.net
PS C:\> $azureInstance = "YOURSERVER.database.windows.net"
PS C:\> $azureDatabase = "MYDATABASE"
PS C:\> $server = Connect-DbaInstance -SqlInstance $azureInstance -Database $azureDatabase -AccessToken $azureToken
PS C:\> Invoke-DbaQuery -SqlInstance $server -Query "select 1 as test"
</code></pre>
<p>Connect to an Azure SQL Database or an Azure SQL Managed Instance with an AccessToken.<br>
Note that the token is valid for only one hour and cannot be renewed automatically.<br></p>
<h5 id="example-16">Example: 16</h5>
<pre><code>PS C:\> $token = New-DbaAzAccessToken -Type RenewableServicePrincipal -Subtype AzureSqlDb -Tenant $tenantid -Credential $cred
PS C:\> Connect-DbaInstance -SqlInstance sample.database.windows.net -Accesstoken $token
</code></pre>
<p>Uses dbatools to generate the access token for an Azure SQL Database, then logs in using that AccessToken.<br></p>
<h5 id="example-17">Example: 17</h5>
<pre><code>PS C:\> $server = Connect-DbaInstance -SqlInstance srv1 -DedicatedAdminConnection
PS C:\> $dbaProcess = Get-DbaProcess -SqlInstance $server -ExcludeSystemSpids
PS C:\> $killedProcess = $dbaProcess | Out-GridView -OutputMode Multiple | Stop-DbaProcess
PS C:\> $server | Disconnect-DbaInstance
</code></pre>
<p>Creates a dedicated admin connection (DAC) to the default instance on server srv1.<br>
Receives all non-system processes from the instance using the DAC.<br>
Opens a grid view to let the user select processes to be stopped.<br>
Closes the connection.<br></p>
<h3 id="required-parameters">Required Parameters</h3>
<h5 id="sqlinstance">-SqlInstance</h5>
<p>The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances. <br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td>Connstring,ConnectionString</td>
</tr>
<tr>
<td>Required</td>
<td>True</td>
</tr>
<tr>
<td>Pipeline</td>
<td>true (ByValue)</td>
</tr>
<tr>
<td>Default Value</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="optional-parameters">Optional Parameters</h3>
<h5 id="sqlcredential">-SqlCredential</h5>
<p>Credential object used to connect to the SQL Server Instance as a different user. This can be a Windows or SQL Server account. Windows users are determined by the existence of a backslash, so if you<br />
are intending to use an alternative Windows connection instead of a SQL login, ensure it contains a backslash.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td></td>
</tr>
</tbody>
</table>
<h5 id="database">-Database</h5>
<p>The database(s) to process. This list is auto-populated from the server.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>(Get-DbatoolsConfigValue -FullName 'sql.connection.database')</td>
</tr>
</tbody>
</table>
<h5 id="applicationintent">-ApplicationIntent</h5>
<p>Declares the application workload type when connecting to a server.<br />
Valid values are "ReadOnly" and "ReadWrite".<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td></td>
</tr>
<tr>
<td>Accepted Values</td>
<td>ReadOnly,ReadWrite</td>
</tr>
</tbody>
</table>
<h5 id="azureunsupported">-AzureUnsupported</h5>
<p>Terminate if Azure is detected but not supported<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>False</td>
</tr>
</tbody>
</table>
<h5 id="batchseparator">-BatchSeparator</h5>
<p>A string to separate groups of SQL statements being executed. By default, this is "GO".<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td></td>
</tr>
</tbody>
</table>
<h5 id="clientname">-ClientName</h5>
<p>By default, this command sets the client's ApplicationName property to "dbatools PowerShell module - dbatools.io". If you're doing anything that requires profiling, you can look for this client name.<br />
Using -ClientName allows you to set your own custom client application name.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>(Get-DbatoolsConfigValue -FullName 'sql.connection.clientname')</td>
</tr>
</tbody>
</table>
<h5 id="connecttimeout">-ConnectTimeout</h5>
<p>The length of time (in seconds) to wait for a connection to the server before terminating the attempt and generating an error.<br />
Valid values are integers between 0 and 2147483647.<br />
When opening a connection to a Azure SQL Database, set the connection timeout to 30 seconds.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>([Dataplat.Dbatools.Connection.ConnectionHost]::SqlConnectionTimeout)</td>
</tr>
</tbody>
</table>
<h5 id="encryptconnection">-EncryptConnection</h5>
<p>If this switch is enabled, SQL Server uses SSL encryption for all data sent between the client and server.<br />
Beginning in .NET Framework 4.5, when TrustServerCertificate is false and EncryptConnection is true, the server name (or IP address) in a SQL Server SSL certificate must exactly match the server name<br />
(or IP address) specified in the connection string. Otherwise, the connection attempt will fail. For information about support for certificates whose subject starts with a wildcard character (*), see<br />
Accepted wildcards used by server certificates for server authentication. <a href="https://support.microsoft.com/en-us/help/258858/accepted-wildcards-used-by-server-certificates-for-server-authenticati">https://support.microsoft.com/en-us/help/258858/accepted-wildcards-used-by-server-certificates-for-server-authenticati</a><br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>(Get-DbatoolsConfigValue -FullName 'sql.connection.encrypt')</td>
</tr>
</tbody>
</table>
<h5 id="failoverpartner">-FailoverPartner</h5>
<p>The name of the failover partner server where database mirroring is configured.<br />
If the value of this key is "" (an empty string), then Initial Catalog must be present in the connection string, and its value must not be "".<br />
The server name can be 128 characters or less.<br />
If you specify a failover partner but the failover partner server is not configured for database mirroring and the primary server (specified with the Server keyword) is not available, then the<br />
connection will fail.<br />
If you specify a failover partner and the primary server is not configured for database mirroring, the connection to the primary server (specified with the Server keyword) will succeed if the primary<br />
server is available.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td></td>
</tr>
</tbody>
</table>
<h5 id="locktimeout">-LockTimeout</h5>
<p>Sets the time in seconds required for the connection to time out when the current transaction is locked.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>0</td>
</tr>
</tbody>
</table>
<h5 id="maxpoolsize">-MaxPoolSize</h5>
<p>Sets the maximum number of connections allowed in the connection pool for this specific connection string.<br></p>
<table>
<thead>
<tr>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>Alias</td>
<td></td>
</tr>
<tr>
<td>Required</td>
<td>False</td>
</tr>
<tr>
<td>Pipeline</td>
<td>false</td>
</tr>
<tr>
<td>Default Value</td>
<td>0</td>
</tr>
</tbody>
</table>
<h5 id="minpoolsize">-MinPoolSize</h5>
<p>Sets the minimum number of connections allowed in the connection pool for this specific connection string.<br></p>
<table>
<thead>