0% found this document useful (0 votes)
34 views

Lab Answer Key: Module 11: Introduction To Managing SQL Server Using Powershell Lab: Using Powershell To Manage SQL Server

The document provides instructions for using PowerShell to manage SQL Server by having users prepare their lab environment, learn how to use PowerShell help, and explore common PowerShell cmdlets related to SQL Server like Get-ChildItem, Remove-*, Get-Command, and Get-Item. The tasks guide users through starting PowerShell with elevated privileges, updating PowerShell help files, displaying help for specific cmdlets, listing cmdlets by verb or including certain terms, and using tab completion. The overall aim is to introduce basic PowerShell functionality and commands useful for managing SQL Server.

Uploaded by

Luis Correa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Lab Answer Key: Module 11: Introduction To Managing SQL Server Using Powershell Lab: Using Powershell To Manage SQL Server

The document provides instructions for using PowerShell to manage SQL Server by having users prepare their lab environment, learn how to use PowerShell help, and explore common PowerShell cmdlets related to SQL Server like Get-ChildItem, Remove-*, Get-Command, and Get-Item. The tasks guide users through starting PowerShell with elevated privileges, updating PowerShell help files, displaying help for specific cmdlets, listing cmdlets by verb or including certain terms, and using tab completion. The overall aim is to introduce basic PowerShell functionality and commands useful for managing SQL Server.

Uploaded by

Luis Correa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

30/1/2019 Librería

Lab Answer Key: Module 11: Introduction to Managing


SQL Server Using PowerShell
Es
te
do
cu
Lab: Using
me
nto
pe
PowerShell to Manage SQL Server
rte
No lui ne
es sg ce
tán u ille aL
pe rm uis
rm oc G
Exercise 1: Getting
as ea Started
@
uil
ler
m
with PowerShell
itid orr
las gm oC
co ail orr
pia .co ea
ss m Lo
in pe
au ra.
tor
Task 1: Prepare the Lab Environment
iza
c ión
.

1. Ensure that the 20764C-MIA-DC and 20764C-MIA-SQL virtual machines are


Eboth
ste
running, and then log on to 20764C-MIA-SQL as
do
ADVENTUREWORKS\Student
cu
me
with the password Pa55w.rd.
nto
pe
rte
2. Ino ethe D:\Labfiles\Lab11\Starter
N l u isg ne
ce folder, right-click Setup.cmd, and then click
stá uil aL
np ler uis
Run aseradministrator.
mi
mo
co Gu
tid rre ille
as a @ rm
las gm oC
co a orr
3. In the User Account pia
ss
Control
il.c
om dialog
ea box, click Yes, and wait for the script to
Lo
in pe
finish. au
tor
ra.
iza
ció
n.

Task E2: Using PowerShell Help


ste
do
cu
me
nto
ert p
1. On
No the luStart
i
menu,
en
e type, Windows PowerShell, right click, Windows
es sg ce
tán ille u a
PowerShell,
pe rmthen Lclick
o
uis Run as administrator.
rm co Gu
itid rre ille
as a@ rm
las
Co dialog box, click Yes. gm o
2. In the User Account
co
p Control
ail
.c rre
ias om aL
sin op
au era
tor .
3. In the console, type Update-Help,
iza
c
and then press Enter. Wait for the help files
ión
.
to update.

4. At the command prompt, type Get-Help, and then press Enter to display the
https://skillpipe.com/?lang=es-ES#/reader/book/24820548-a5cd-4cbe-80fd-0658d7f0f8c4 1/5
30/1/2019 Librería

summary help page.

5. At the command prompt, type Get-Help Get-ChildItem, and then press Enter to
display help for the cmdlet.

6. At the command prompt, type Get-Command Remove-*, and then press Enter
Es
te
do a list of all the cmdlets that start with the verb Remove-.
to get
cu
me
nto
pe
rte
7. At
No the command
lui
s
ne prompt, type Get-Command *sql*, and then press Enter to get
c
es gu ea
tán ille Lu
a list ofeall
p
rm
the ocmdlets
r m
co
is that include “sql”.
Gu
itid rre ille
as a@ rm
las gm oC
8. At the commandopprompt, c
ias
a il.c type
om
orrGet-Item,
ea and then press TAB to view tab-
sin Lo
pe
completion of the cmdlet. au
tor
ra.
iza
ció
n.
9. Press ESC to clear the command.

Es
te
do
cu
me PowerShell Providers
Task 3: Using
nto
pe
rte
No lui ne
es sg ce
tán u ille aL
pe rm uis
oc
Gu type Get-PsProvider, and then press Enter to list the
1. At the command
rm
itid orrprompt,
e ille
as a@ rm
oC
gmand valid las
PowerShell providers
co ail orr locations.
pia .co ea
ss m Lo
in pe
au . ra
2. At the command prompt,toritype
za Set-Location Env:, and then press Enter to go to
ció
n .
the Environment location.

3. At the command prompt, type Get-ChildItem, and then press Enter to list the
Econtents
ste
of the location.
do
cu
me
4. At the command nto
pe
prompt, type Get-PSDrive, and then press Enter to list the
rte
No
available lui drives. ne
es sg ce
tán uil aL
ler uis
pe mo
rm co Gu
5. Compare itthe ida PSDrives
sl
rre
a @
ille
with
rm the PSProviders.
oC
as gm
co ail orr
pia .co ea
ss m Lo
6. At the command prompt, in
au type Import-Module
pe
ra. SQLPS, and then press Enter to
tor
iza
import the SQL PowerShell cimodule.
ón You can ignore any warnings that appear.
.

7. At the command prompt, type Get-PsProvider, and then press Enter to list the
PowerShell providers. Note that SqlServer now appears in the list.
https://skillpipe.com/?lang=es-ES#/reader/book/24820548-a5cd-4cbe-80fd-0658d7f0f8c4 2/5
30/1/2019 Librería

8. At the command prompt, type Get-PSDrive, and then press Enter to list the
available drives. Note that SqlServer now appears in the list.

9. At the command prompt, type Get-Help Get-PSProvider, press Enter, and then
read the returned information to learn more about the PSProvider cmdlet.
Es
te
do
c
10. At theumcommand
en
t
prompt, type Get-Help Get-PSDrive, press Enter, and then
op
ert
read
No the
lui returned
en
e information to learn more about the PSDrive cmdlet.
es sg ce
tán u ille aL
pe rm uis
rm Gu oc
11. At the command
itid
a
orrprompt,
ea ille type Exit to close the console.
r sl @ mo
as gm Co
co ail rre
pia .co aL
ss m op
in era
au .
tor
iza
ció
Result: After completing this exercise,
. you will have investigated PowerShell help
n

and the SQL PowerShell provider.

Es
ed t
Exerciseoc 2: Using PowerShell to Change SQL Server Settings
um
en
to
pe
rte
No lui ne
es sg ce
tán u ille a
Task 1: View
pe Database
rm
o
LuSettings
is
rm co Gu
itid rre ille
as a@ rm
las gm oC
orr co ail
ea pia .co
ss m Lo
1. On the Start menu, type
in
au
Windows pPowerShell,
era right-click Windows
tor .
PowerShell, and then click iza Run ISE as Administrator.
ció
n.

2. In the User Account Control dialog box, click Yes.

3. EOn the File menu, click Open.


ste
do
cu
me
4. In the Open nto dialog box, navigate to D:\Labfiles\Lab11\Starter, click
pe
rte
DisplayProperties.ps1,
No
es
lui
sg
ne
ce and then click Open.
tán uil aL
ler uis
pe mo
rm co Gu
5. Select theitidcode as
rre
under
a@ the
ille #1# comment, and then on the toolbar, click Run
rm
las gm oC
co ail orr
Selection to display pia “import
ss
.co
m
the ea SQL module”. Ignore any warnings that may
Lo
in pe
appear. au
tor
ra.
iza
ció
n.
6. Select the code under the #2# comment, and then on the toolbar, click Run
Selection to change the location.

https://skillpipe.com/?lang=es-ES#/reader/book/24820548-a5cd-4cbe-80fd-0658d7f0f8c4 3/5
30/1/2019 Librería

7. Select the code under the #3# comment, and then on the toolbar, click Run
Selection to get the database object.

8. Select the code under the #4# comment, and then on the toolbar, click Run
Selection to display the database properties.
Es
te
9. do the code under the #5# comment, and then on the toolbar, click Run
Select
cu
me
n
to to display the database option.
Selection pe
r
No lui ten
sg ec
es u ea
tán ille Lu
pe rm is
rm oc Gu
itid orr ille
as ea rm
las @ oC
gm
co orr
ail
.co
pia ea
Task 2: Amend Database
s sin Settings Lope
m
au ra.
tor
iza
ció
n.
1. On the File menu, click Open.

2. In the Open dialog box, navigate to D:\Labfiles\Lab11\Starter, click


Es
te
ChangeProperties.ps1, and then click Open.
do
c um
en
to
ert p
3. Select
N the
lu codeen under the #1# comment, and then on the toolbar, click Run
e
oe isg ce
stá ito aL u
Selection
np lle prepare
rm uis the script.
erm oc Gu
itid orrille
as ea rm
las @
oC
4. Select the g
codecoundermathe
pia il.c #2# orr comment,
ea
and then on the toolbar, click Run
ss om Lo
Selection to change nthe
i
au location. era.
p
tor
iza
ció
n.
5. Select the code under the #3# comment, and then on the toolbar, click Run
Selection to get the database object.

6. ESelect
ste
the code under the #4# comment, and then on the toolbar, click Run
do
Selection
cu
me to change the compatibility level of the AdventureWorks2016
nto
database. perte
No lui ne
es sg ce
tán uil aL
ler uis
7. Selectpthe erm code mo under
co Guthe #5# comment, and then on the toolbar, click Run
itid rre ille
as a@ rm
Selection to lchange as
co
gmthe
ail
ANSI
o C nulls, autoshrink, read only, and recovery model
orr
pia .co ea
options. ss
in
m Lo
pe
au ra.
tor
iza
ció
n.

Task 3: View and Amend Server Settings


https://skillpipe.com/?lang=es-ES#/reader/book/24820548-a5cd-4cbe-80fd-0658d7f0f8c4 4/5
30/1/2019 Librería

1. On the File menu, click Open.

2. In the Open dialog box, navigate to D:\Labfiles\Lab11\Starter, click


ChangeServerSettings.ps1, and then click Open.

3. Select the code under the #1# comment, and then on the toolbar, click Run
Es
te
do
Selection to display “import the SQL module”. Ignore any warnings that may
cu
m en
to
appear. pe
rte
No lui ne
es sgce
tán u aL
ille
4. Select the uis the #2# comment,
erm code oc under and then on the toolbar, click Run
p r m
orr Gu
itid ea ille
a
Selection to lchange
s @ the rlocation.
mo
as gm Co
co ail rre
pia .co aL
ss m op
in era
5. Select the code underathe uto #3# comment, . and then on the toolbar, click Run
riz
ac
Selection to get the server object. ión
.

6. Select the code under the #4# comment, and then on the toolbar, click Run
Selection to display the Settings object.
Es
te
do
c
7. Selectumthe
en code under the #5# comment, and then on the toolbar, click Run
to
ert p
Selection
N lu to echange
ne the login mode to mixed authentication.
oe isg ce
stá uil aL
np ler uis
erm mo
8. Guthe #6# comment, and then on the toolbar, click Run
Select theitidcodecounder
rre ille
as a@ rm
gm las o
Selection to change
co
p
the
ail login
.
Co mode back to integrated authentication.
rre
ias co aL
op
sin m
era
au
t .
9. Select the code under theriza#7# comment,
o and then on the toolbar, click Run
ció
n.
Selection to examine the UserOptions object.

10. Select the code under the #8# comment, and then on the toolbar, click Run
ESelection
ste
to change some server settings.
do
cu
me
11. Select the nto code under the #9# comment, and
pe then on the toolbar, click Run
rte
N l u ne
Selection
oe
stá
isg to reset
uil
ce the server settings.
l erm aL
np uis
erm oc Gu
itid o rre ille
12. On the File amenu,
sl a click
@ Exit.
rm
oC
as gm
co ail orr
pia .co ea
ss m Lo
in pe
au ra.
tor
iza
ció
n.
Result: After completing this lab exercise, you will have PowerShell scripts to
show the IT Director.

https://skillpipe.com/?lang=es-ES#/reader/book/24820548-a5cd-4cbe-80fd-0658d7f0f8c4 5/5

You might also like