Your SlideShare is downloading. ×
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Power shell for sql server
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Power shell for sql server

2,294

Published on

Unleashing Powershell to

Unleashing Powershell to

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
2,294
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
21
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. PowerShell for SQL Server
    Leonard Mwangi MCDBA, MCTS
    eTek Global Inc.
  • 2. Agenda
    Introduction to PowerShell
    Lifecycle
    Language
    Usability
    PowerShell with SQL
    PowerShell difficulties
  • 3. Introduction
    Command-line shell with an associated scripting language for automation.
    Heavily integrated with .NET Framework.
    Provides full access to COM and WMI allowing local and remote administration of Windows Systems.
    Commands referred to as cmdlets - .NET Classes allowing implementation of specific operations.
    Utilized by most Microsoft applications and Systems (Windows Server, MSSQL, Exchange Server, SCOM, SCDMP etc.
  • 4. Lifecycle
    Code name “Monad” – Sept 2003
    Version 1.0 released 2006 for Windows XP SP2/SP3
    Version 2.0 Integrated with Windows 7 and Window Server 2008 R2.
    Downloadable for earlier versions of Windows.
    Can execute four kinds of commands.
    Cmdlets – specialized commands implementing specific functions.
    PowerShell scripts – suffixed as .ps1
    PowerShell functions
    Executable programs
  • 5. Language
    .Net Aspect
    Property -- can get
    Method -- can do
    CMDLETS
    Integrated with command Line
    Built with WMI in mind.
    Language format – verb-noun
    Arranged in hard drives
    Variables
  • 6. Scripting
    Getting RAM from Local Machine
    Get-WmiObject Win32_ComputerSystem
    Getting RAM from Local Machine
    Option ExplicitDim objWMIService, objComputer, colComputerDim strLogonUser, strComputer
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _& "{impersonationLevel=impersonate}!quot; _ & strComputer & " ootcimv2") Set colComputer = objWMIService.ExecQuery _("Select * from Win32_ComputerSystem")
    For Each objComputer in colComputerWscript.Echo "System Name: " & objComputer.Name _& vbCr & "Total RAM " & objComputer.TotalPhysicalMemoryNext
    WScript.Quit
  • 7. Usability - basics
    Functions like DOS
    Store everything as a drive
    psdrive
    Variables
    $varname
    Displaying you variables after assigning it
    $dt = Get-Date | $dt – Wont work
    $dt = Get-Date ; $dt
    Can pass doss command to PowerShell
    $varname = "Localhost“
    Piping and Pipeline
    Get-Service | Sort-Object -Property ServiceType | Format-Table name, ServiceType, status, CanStop, -Auto
    Filtering
    Get-Service | Where {$_.Status -eq "Stopped"} | ft name, status, CanStop -AutoSize
    Looping
    For-each {$_.} -- current iteration of the loop
  • 8. Usability - basics
    Get-Member
    Using Alias
    New-Alias myalias Get-Service
    Reference previously used commands
    get-history
    Signing Scripts – configured to run in most secure mode (Restricted)
    AllSigning, RemoreSigned, UnRestricted
    HELP
  • 9. PowerShell & SQL
    SQLPS – accessible from any where in SSMS
    dir| Get-Member
    From a table
    dir | ft Name, RowCount, State, Owner, Triggers
    SQL Server Management Objects (SMO) – Objects collections for SQL Server Management.
    [reflection.assembly]::LoadWithPartialName("Microsoft.SQLServer.SMO")
    Assign variables
  • 10. Useful SMO’s
  • 11. Question & Answer Session
  • 12. References
    http://technet.microsoft.com/en-us/library/ee221100.aspx - Owners Manual
    http://technet.microsoft.com/en-us/library/ee176868.aspx - PowerShell shortcuts
    http://technet.microsoft.com/en-us/scriptcenter/powershell.aspx -- PowerShell
    http://www.microsoft.com/downloads/en/details.aspx?FamilyId=DF8ED469-9007-401C-85E7-46649A32D0E0&displaylang=en – PowerShell cheatSheet
    http://gallery.technet.microsoft.com/ScriptCenter/en-us/ - Microsoft Script Center
    http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx - SMO Classes
  • 13. Thank you for coming
    Email:- leonard.mwangi@etekglobalinc.com
    Site:- www.etekglobalinc.com
    Blog:- www.geekswithblogs.netleonardm
    LinkedIn:- http://www.linkedin.com/in/lmundia
    Twitter:- lmundia

×