Đang chuẩn bị liên kết để tải về tài liệu:
Microsoft SQL Server 2008 R2 Unleashed- P56
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft SQL Server 2008 R2 Unleashed- P56:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major releases.Microsoft SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 494 CHAPTER 17 Administering SQL Server 2008 with PowerShell Passing Arguments PowerShell has a special reserved variable named args. It can be used with scripts and functions and represents any arguments passed to the script or function when it is invoked as shown here PS add-content c temp parameter.ps1 args.count PS add-content c temp parameter.ps1 args 0 PS c temp parameter.ps1 1 2 3 3 1 PS In the preceding example a two-line script is created and then it is invoked while passing some arguments to it. args.count displays the number of arguments passed to the script whereas args 0 displays the value of the first argument only. Later an example of a PowerShell script that can do a database backup is provided. The example is extended to show how a script could be used to accept an argument that would be the name of the database the script will back up. Using Param A special construct param can be used to force the way arguments are passed to a script or function PS function test_param param string arg1 write-host Argument 1 is arg1 PS test_param testing Argument 1 is testing PS test_param -arg1 testing Argument 1 is testing PS In this example param is used to specify that a parameter passed to this script will be a string object and will be contained in the variable arg1 for later use in the script. NOTE The biggest difference between using param or args with arguments occurs when the number of arguments is known versus unknown. The param keyword should not be used when the number of arguments passed is not known. Download from www.wowebook.com PowerShell Scripting Basics 495 NOTE string i s a shortcut in PowerShell where you specify that the argument as in the preceding example will be a string and not something else such as a number or integer. A dozen or so of these shortcuts are available in PowerShell and they are typically known as type accelerators. Arrays To PowerShell arrays are simply a listing of data. They can be used for various tasks and can be .