SlideShare a Scribd company logo
Why Use PowerShell(demo)Siraj Jamdar
Invoke PowerShellFrom the command line:Windows+R-> sqlpsLimited shell by design (to protect the innocent from themselves)
Invoke PowerShell from SQLContext sensitive in SSMSRight-Click -> pick Start PowerShelloptionMy favourite, pretty snappy and usefulAutomatically traverses to the correct level
Invoke PowerShell from SQLAgentSQL Agent Job StepPick PowerShell from the Type dropdown list and paste the script in the boxDreadfully slow… I’d use an SSIS package insteadUse windows scheduler, better integration with Event Viewer logsSCOM raises alerts from Event Viewer logs
Invoke PowerShellThe hard wayStart  All Programs
Accessories
Windows PowerShell
Windows PowerShellPowerShellcorrupts ;-)
Invoke PowerShellTo get any real work done …runas /noprofile /user:anotherDomain\JamdarSi_adm %SystemRoot%\system32\WindowsPowerShell\ v1.0\powershell.exerunas /noprofile /user:yetanotherDomain\SJamdar%SystemRoot%\system32\WindowsPowerShell\  v1.0\powershell.exeFlex your muscles now…N.B. PowerShell 2.0 still refers to v1.0 path for backward compatibility
In real life Gotchas:Firewall is not blocking portsFirewall is not dropping packetsCorrect trust relationships are set up between AD domainsGrab the swiss ball, we’re doing Pilates now…
Check SQL SnapinsPS H:\> Get-PSSnapin -registeredName        : SqlServerCmdletSnapin100PSVersion   : 2.0Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.Name        : SqlServerProviderSnapin100PSVersion   : 2.0Description : SQL Server Provider
Load SQL SnapinsAdd-PSSnapin SqlServerProviderSnapin100Add-PSSnapin SqlServerCmdletSnapin100
Load SMO assembliesThe hard way :[Reflection.Assembly]::Load( 		` "Microsoft.SqlServer.Smo, 		`Version=10.0.0.0, Culture=neutral, 	`PublicKeyToken=89845dcd8080cc91")# connect to SQL Server named instance# server name is L50011051# instance name is Instance1$serverName = "L50011051\Instance1"$server = New-Object –typeName 		  ` Microsoft.SqlServer.Management.Smo.Server `-argumentList "$serverName"Is there an easier way?
Load SMO assembliesThe easier way :[System.Reflection.Assembly]::LoadWithPartialName(	` 'Microsoft.SqlServer.SMO') | out-null# This time connect to default instance# server name is L50011051# and pass in a literal$server = New-Object(					` 'Microsoft.SqlServer.Management.Smo.Server') 	`"L50011051" Let PowerShell do the heavy lifting with .net assemblies & reflection API
Load AMO assembliesSlightly different syntax:[Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.AnalysisServices")$as=New-Object Microsoft.AnalysisServices.Server$as.connect("L50011051")$as | Format-ListTeaser for a separate demo on PowerShell to administer Analysis Services (volunteers please…)
Other SMO assemblies#Need SmoExtended for smo.backup[System.Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.SqlServer.SmoExtended") | Out-Null[System.Reflection.Assembly]::LoadWithPartialName( `	"Microsoft.SqlServer.ConnectionInfo") | Out-Null# 2005 specific, not available in 2008. # Use common instead[System.Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.SqlServer.SmoEnum") | Out-Nullhttp://sqlblog.com/blogs/allen_white/archive/2008/12/07/loading-smo-assemblies-into-powershell.aspx

More Related Content

What's hot (19)

PDF
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
PPTX
Mule esb How to convert from Json to Xml in 5 minutes
Gennaro Spagnoli
 
PPTX
How to do everything with PowerShell
Juan Carlos Gonzalez
 
PPTX
From Web Developer to Hardware Developer
alexshenoy
 
PDF
How To Check file exists and Delete PowerShell
VCP Muthukrishna
 
PDF
Deploy agent in em12c
Osama Mustafa
 
PDF
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
PDF
Add target manually em12c
Osama Mustafa
 
PPTX
Supplemental explanation WebSocket Demo.
Norio Kobota
 
PDF
Install and Configure RSyslog – CentOS 7 / RHEL 7
VCP Muthukrishna
 
PDF
How To Install and Configure AWS CLI for Windows
VCP Muthukrishna
 
PPTX
2018 Student360 - Beyond xp_cmdshell - Owning the Empire Through SQL Server
Scott Sutherland
 
PDF
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
PPTX
Secure360 - Beyond xp cmdshell - Owning the Empire through SQL Server
Scott Sutherland
 
PPTX
Input and output flow using http and java component
Son Nguyen
 
PPTX
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
Scott Sutherland
 
PPTX
2017 Thotcon - Hacking SQL Servers on Scale with PowerShell
Scott Sutherland
 
PPTX
Admin share point with powershell
Concentrated Technology
 
PPTX
Mule esb db_2
Davide Rapacciuolo
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
VCP Muthukrishna
 
Mule esb How to convert from Json to Xml in 5 minutes
Gennaro Spagnoli
 
How to do everything with PowerShell
Juan Carlos Gonzalez
 
From Web Developer to Hardware Developer
alexshenoy
 
How To Check file exists and Delete PowerShell
VCP Muthukrishna
 
Deploy agent in em12c
Osama Mustafa
 
How To Install and Configure Open SSH Server on Ubuntu
VCP Muthukrishna
 
Add target manually em12c
Osama Mustafa
 
Supplemental explanation WebSocket Demo.
Norio Kobota
 
Install and Configure RSyslog – CentOS 7 / RHEL 7
VCP Muthukrishna
 
How To Install and Configure AWS CLI for Windows
VCP Muthukrishna
 
2018 Student360 - Beyond xp_cmdshell - Owning the Empire Through SQL Server
Scott Sutherland
 
How To Connect to Active Directory User Validation
VCP Muthukrishna
 
Secure360 - Beyond xp cmdshell - Owning the Empire through SQL Server
Scott Sutherland
 
Input and output flow using http and java component
Son Nguyen
 
2016 aRcTicCON - Hacking SQL Server on Scale with PowerShell (Slide Updates)
Scott Sutherland
 
2017 Thotcon - Hacking SQL Servers on Scale with PowerShell
Scott Sutherland
 
Admin share point with powershell
Concentrated Technology
 
Mule esb db_2
Davide Rapacciuolo
 

Viewers also liked (20)

PPTX
Finding Your Internship
billmorgan231
 
PPT
149 amazing pictures
thandastuff
 
PDF
Introducing VALS project & Semester of Code
Grial - University of Salamanca
 
PPT
Foxworth Portfolio
Foxworth Advertising
 
PPTX
World Internet Project Czech republic 2014 Preliminary data presentation
Petr Lupac
 
PPS
Happiness
thandastuff
 
PDF
Iso 9001 2008-_es_
Landy Delgadillo Pérez
 
PDF
Frenchaccounts2009 theaccountingreform
Ministère de l'Économie et des Finances
 
PPTX
Research Perfection
Julie Anne Kent
 
PDF
VALS WP7 – Dissemina1on Status at Bolton meeting
Grial - University of Salamanca
 
PDF
Yangtze
Mountainscribe
 
PDF
IndustriKvarteret - Podcast for virksomheder
Brønderslev Erhverv
 
PDF
mobility.ifsworld.com - Mobilita mění Vaše podnikání (1)
IFS Czech
 
PPTX
The Creative Economy within the United States of America
Tyrone Grandison
 
PDF
VALS - FIE 2014 (Frontiers in Education Conference)
Grial - University of Salamanca
 
PDF
Are nonusers socially disadvantaged?
Petr Lupac
 
PPTX
Are we all knowledgeable now
Petr Lupac
 
PDF
Embedded blogging
vogmae
 
PPTX
Log into glogster edu
InfowhizDCSD
 
PPT
Esperanzas
vaonaaitor
 
Finding Your Internship
billmorgan231
 
149 amazing pictures
thandastuff
 
Introducing VALS project & Semester of Code
Grial - University of Salamanca
 
Foxworth Portfolio
Foxworth Advertising
 
World Internet Project Czech republic 2014 Preliminary data presentation
Petr Lupac
 
Happiness
thandastuff
 
Iso 9001 2008-_es_
Landy Delgadillo Pérez
 
Frenchaccounts2009 theaccountingreform
Ministère de l'Économie et des Finances
 
Research Perfection
Julie Anne Kent
 
VALS WP7 – Dissemina1on Status at Bolton meeting
Grial - University of Salamanca
 
IndustriKvarteret - Podcast for virksomheder
Brønderslev Erhverv
 
mobility.ifsworld.com - Mobilita mění Vaše podnikání (1)
IFS Czech
 
The Creative Economy within the United States of America
Tyrone Grandison
 
VALS - FIE 2014 (Frontiers in Education Conference)
Grial - University of Salamanca
 
Are nonusers socially disadvantaged?
Petr Lupac
 
Are we all knowledgeable now
Petr Lupac
 
Embedded blogging
vogmae
 
Log into glogster edu
InfowhizDCSD
 
Esperanzas
vaonaaitor
 
Ad

Similar to Demo for Why Use PowerShell (6)

PDF
Get database properties using power shell in sql server 2008 techrepublic
Kaing Menglieng
 
PDF
SQL Track: Restoring databases with powershell
ITProceed
 
PPTX
My first powershell script
David Cobb
 
PPTX
Powershell Tech Ed2009
rsnarayanan
 
PPTX
Windows PowerShell - Billings .NET User Group - August 2009
John Clayton
 
PPT
SharePoint Administration with PowerShell
Eric Kraus
 
Get database properties using power shell in sql server 2008 techrepublic
Kaing Menglieng
 
SQL Track: Restoring databases with powershell
ITProceed
 
My first powershell script
David Cobb
 
Powershell Tech Ed2009
rsnarayanan
 
Windows PowerShell - Billings .NET User Group - August 2009
John Clayton
 
SharePoint Administration with PowerShell
Eric Kraus
 
Ad

Recently uploaded (20)

PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PPTX
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
PPTX
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
“Scaling i.MX Applications Processors’ Native Edge AI with Discrete AI Accele...
Edge AI and Vision Alliance
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Dev Dives: Accelerating agentic automation with Autopilot for Everyone
UiPathCommunity
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Unlocking FME Flow’s Potential: Architecture Design for Modern Enterprises
Safe Software
 
Practical Applications of AI in Local Government
OnBoard
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
The birth and death of Stars - earth and life science
rizellemarieastrolo
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
How to Comply With Saudi Arabia’s National Cybersecurity Regulations.pdf
Bluechip Advanced Technologies
 
Smart Factory Monitoring IIoT in Machine and Production Operations.pptx
Rejig Digital
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 

Demo for Why Use PowerShell

  • 2. Invoke PowerShellFrom the command line:Windows+R-> sqlpsLimited shell by design (to protect the innocent from themselves)
  • 3. Invoke PowerShell from SQLContext sensitive in SSMSRight-Click -> pick Start PowerShelloptionMy favourite, pretty snappy and usefulAutomatically traverses to the correct level
  • 4. Invoke PowerShell from SQLAgentSQL Agent Job StepPick PowerShell from the Type dropdown list and paste the script in the boxDreadfully slow… I’d use an SSIS package insteadUse windows scheduler, better integration with Event Viewer logsSCOM raises alerts from Event Viewer logs
  • 5. Invoke PowerShellThe hard wayStart All Programs
  • 9. Invoke PowerShellTo get any real work done …runas /noprofile /user:anotherDomain\JamdarSi_adm %SystemRoot%\system32\WindowsPowerShell\ v1.0\powershell.exerunas /noprofile /user:yetanotherDomain\SJamdar%SystemRoot%\system32\WindowsPowerShell\ v1.0\powershell.exeFlex your muscles now…N.B. PowerShell 2.0 still refers to v1.0 path for backward compatibility
  • 10. In real life Gotchas:Firewall is not blocking portsFirewall is not dropping packetsCorrect trust relationships are set up between AD domainsGrab the swiss ball, we’re doing Pilates now…
  • 11. Check SQL SnapinsPS H:\> Get-PSSnapin -registeredName : SqlServerCmdletSnapin100PSVersion : 2.0Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.Name : SqlServerProviderSnapin100PSVersion : 2.0Description : SQL Server Provider
  • 12. Load SQL SnapinsAdd-PSSnapin SqlServerProviderSnapin100Add-PSSnapin SqlServerCmdletSnapin100
  • 13. Load SMO assembliesThe hard way :[Reflection.Assembly]::Load( ` "Microsoft.SqlServer.Smo, `Version=10.0.0.0, Culture=neutral, `PublicKeyToken=89845dcd8080cc91")# connect to SQL Server named instance# server name is L50011051# instance name is Instance1$serverName = "L50011051\Instance1"$server = New-Object –typeName ` Microsoft.SqlServer.Management.Smo.Server `-argumentList "$serverName"Is there an easier way?
  • 14. Load SMO assembliesThe easier way :[System.Reflection.Assembly]::LoadWithPartialName( ` 'Microsoft.SqlServer.SMO') | out-null# This time connect to default instance# server name is L50011051# and pass in a literal$server = New-Object( ` 'Microsoft.SqlServer.Management.Smo.Server') `"L50011051" Let PowerShell do the heavy lifting with .net assemblies & reflection API
  • 15. Load AMO assembliesSlightly different syntax:[Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.AnalysisServices")$as=New-Object Microsoft.AnalysisServices.Server$as.connect("L50011051")$as | Format-ListTeaser for a separate demo on PowerShell to administer Analysis Services (volunteers please…)
  • 16. Other SMO assemblies#Need SmoExtended for smo.backup[System.Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.SqlServer.SmoExtended") | Out-Null[System.Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.SqlServer.ConnectionInfo") | Out-Null# 2005 specific, not available in 2008. # Use common instead[System.Reflection.Assembly]::LoadWithPartialName( ` "Microsoft.SqlServer.SmoEnum") | Out-Nullhttp://sqlblog.com/blogs/allen_white/archive/2008/12/07/loading-smo-assemblies-into-powershell.aspx
  • 17. SQL Authentication# $True for integrated security # $False for SQL authentication, meaning # supply username & password at the prompt$server.ConnectionContext.LoginSecure=$false; $credential = Get-Credential$userName = $credential.UserName –replace("\\", "")$server.ConnectionContext.set_Login($userName)$server.ConnectionContext.set_SecurePassword( ` $credential.Password)Write-Host $svr.ConnectionContext.ConnectionStringHorror story here!!!Customise sp_who$server.EnumProcesses() | `?{$_.IsSystem -eq $False -and $_.Login -eq 'sa'} | ` Select Spid, Login, Status, Cpu, MemUsage, | ` BlockingSpid, Database, Host, Command, Program | `Format-Table -auto -wrapUser spid’s onlyPick which columns to displayRe-order them, narrower columns first