Creating a PowerShell Script

Creating a PowerShell script is as simple as placing a few commands into a .ps1 script and then invoking that script. Here’s a simple example of putting the Write-Host cmdlet into a script and then running it.

image

In the preceding example, a Write-Host cmdlet was placed in a file named test.ps1, and then the file was invoked. The output resulted in the string "testing" being output to the script. Notepad or any other simple text editor could also be used to create more complicated scripts.

Sample PowerShell scripts that directly apply to SQL Server administration are provided later in this chapter. Refer to the "The Step-By-Step ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.