Skip to content

Commit e682883

Browse files
updated snippets
1 parent 4e4bef1 commit e682883

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Snippets List.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,51 @@ $snippet = @{
7272
"@
7373
}
7474
New-IseSnippet @snippet
75+
76+
$snippet = @{
77+
Title = 'Prompt for input'
78+
Description = 'Simple way of gathering input from users with simple yes and no'
79+
Text = @"
80+
# Get some input from users
81+
`$title = "Put your Title Here"
82+
`$message = "Put Your Message here (Y/N)"
83+
`$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Will continue"
84+
`$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Will exit"
85+
`$options = [System.Management.Automation.Host.ChoiceDescription[]](`$yes, `$no)
86+
`$result = `$host.ui.PromptForChoice(`$title, `$message, `$options, 0)
87+
88+
if (`$result -eq 1)
89+
{ Write-Output "User pressed no!"}
90+
elseif (`$result -eq 0)
91+
{ Write-Output "User pressed yes!"}
92+
"@
93+
}
94+
New-IseSnippet @snippet
95+
96+
$snippet = @{
97+
Title = 'Run SQL query with SMO'
98+
Description = 'creates SMO object and runs a sql command'
99+
Text = @"
100+
`$srv = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList `$Server
101+
`$SqlConnection = `$srv.ConnectionContext
102+
`$SqlConnection.StatementTimeout = 8000
103+
`$SqlConnection.ConnectTimeout = 10
104+
`$SqlConnection.Connect()
105+
`$Results = `$SqlConnection.ExecuteWithResults(`$Query).Tables
106+
`$SqlConnection.Disconnect()
107+
"@
108+
}
109+
New-IseSnippet @snippet
110+
111+
$snippet = @{
112+
Title = 'SQL Assemblies'
113+
Description = 'SQL Assemblies'
114+
Text = @"
115+
[void][reflection.assembly]::LoadWithPartialName( "Microsoft.SqlServer.Management.Common" );
116+
[void][reflection.assembly]::LoadWithPartialName( "Microsoft.SqlServer.SmoEnum" );
117+
[void][reflection.assembly]::LoadWithPartialName( "Microsoft.SqlServer.Smo" );
118+
[void][reflection.assembly]::LoadWithPartialName( "Microsoft.SqlServer.SmoExtended " );
119+
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
120+
"@
121+
}
122+
New-IseSnippet @snippet

0 commit comments

Comments
 (0)