Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

SQLPS Powershell in SQL Server -4

Lets see some more cmdlets

1.Backup-Sqldatabase
first we need to check examples how to use Backup_Sqldatabase

Run this command
Get-Help Backup-Sqldatabase -Examples



It will give us examples
Similarly for all cmdlets we can get examples how to use it.


Now we will run a sample how take backup

Backup-Sqldatabase -Database Test




It will take backup of Database Test.

How to redirect  result to HTML page?

Run this command

 Invoke-Sqlcmd "select * from sys.tables" | ConvertTo-Html > c:\test.html




Lets see the result in browser by opening test.html in browser.


















How to get list of servers running in network using PowerShell

As a DBA its your repsonsibility to get list of SQL Servers running in network and manage them. As infrastructure grows its getting tough to get list of SQL Servers running in network along with their versions
It easy in Powershell
Let see how to use it

SQLPS Powershell in SQL Server -3

Now we will go for some cmdlets and see how to use them.
One question comes in your mind is how to run query from powershell?

Lets see first it
For this there is cmdlet -Invoke-Sqlcmd

SQLPS Powershell in SQL Server -2

Ok , so now we are connected to SQLPS
We will first navigate to different folders of SQL Server

SQLPS - Powershell in SQL Server

Those who are using SQL Server must have idea of Powershell eventhough they dont have used it.
Its a nice utility and sometimes makes work more easy then routine coding.
Here today first we weill get basic idea on how to use it.
Before SQL Server 2012 it was a sepereate exe SQLPS.exe, but 2012 onwards MS has added it as a seperate module for powershell. So eventhough SQLPS is available, it will be deprecated in future.

Popular Posts