#眉標=SQL Server 2008、PowerShell、cmdlet #副標=SQL Server 2008新功能概覽(7) #大標=SQL Server 2008整合PowerShell #作者=文/圖 胡百敬 ===<反灰>============= get-help -detailed ================ ===<反灰>============= SQLSERVER:\SQL\電腦名稱\執行個體名稱 ================ ===<反灰>============= Invoke-Sqlcmd “CREATE TABLE [Table:Test](C1 INT)” ================ ===<反灰>============= Set-Location : 找不到磁碟機。名為 'dbo.[Table' 的磁碟機不存在。 位於 行:1 字元:3 + cd <<<< dbo.[Table:Test] ================ ===<反灰>============= cd (“dbo.” + (Encode-SqlName “Table:Test”)) ================ ===<反灰>============= SQLSERVER:\SQL\MyComputer\DEFAULT\Databases\AdventureWorks\Tables\Person.Address ================ ===<反灰>============= Server[@Name='MyComputer']\Database[@Name='AdventureWorks']\Table[@Name='Address' and @Schema='Person'] ================ ===<反灰>============= gc c:\Servers.txt | % { Invoke-SQLCmd -Server $_ -Query "select @@servername as 'Server', count(*) as 'Blocked' from master.dbo.sysprocesses where blocked <> 0" } ================ ===<反灰>============= select @@servername as 'Server', count(*) as 'Blocked' from master.dbo.sysprocesses where blocked <> 0 ================ ===<反灰>============= tfsrtm tfsrtm2 tfsrtm2\Katmai ================ ===<反灰>============= Add-PSSnapin SqlServerCmdletSnapin100 Add-PSSnapin SqlServerProviderSnapin100 gc c:\Servers.txt | % { Invoke-SQLCmd -Server $_ -Query "select @@servername as 'Server', count(*) as 'Blocked' from master.dbo.sysprocesses where blocked <> 0" } | Out-File -filePath "C:\Blocked.txt ================ ===<反灰>============= Set-ExecutionPolicy Unrestricted ================ ===<反灰>============= C:\powershell.exe test.ps1 ================ ===<反灰>============= 'test.ps1' 詞彙無法辨識是否為Cmdlet、函數、可執行程式或指令檔。請確認該詞彙, 然後再試一次。 位於 行:1 字元:8 + test.ps1 <<<< ================ ===<反灰>============= C:\powershell.exe .\test.ps1 ================ ===<反灰>============= C:\powershell.exe C:\test.ps1 ================ ===<反灰>============= SET PATH=%PATH%;C:\ ================ ===<反灰>============= C:\powershell.exe test.ps1 ================ ===<反灰>============= ftype Microsoft.PowerShellScript.1="C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -command "&{%1}" ================ ===<反灰>============= sl "SQLSERVER:\SQLPolicy\Sql2K8\DEFAULT\Policies" dir | Where-Object {$_.PolicyCategory -eq "Microsoft 最佳作法: 維護"} | Invoke-PolicyEvaluation -TargetServer "SQL2K8" -OutputXML > ("C:\temp\data" + ([DateTime]::Now -Replace '/| |:','') + ".xml") ================ ===<反灰>============= C:\Windows\System32\WindowsPowerShell\v1.0\Documents ================