您好,登錄后才能下訂單哦!
服務器上裝了SQL Server 2014的默認實例,以及SQL Server 2017的命名實例SQL2017
$env:PSModulePath為
%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\
在執行Powershell命令
New-SqlAvailabilityGroup -Name $AgName -InputObject $Primary -AvailabilityReplica $Replicas -Database $DatabaseList
時,報錯如下:
去掉了SQL Server 2014的SQLPS目錄路徑
%SystemRoot%\system32\WindowsPowerShell\v1.0\Modules\;C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\
再加載SQL Server 2017默認的SQLPS,執行New-SqlAvailabilityGroup正常。
說明兩個版本SQLPS里New-SqlAvailabilityGroup對應的參數-InputObject類型有差異。
后記:
后來再嘗試加載SQL Server 2014的SQLPS模塊,針對SQL Server 2014默認實例創建AG失敗。索性直接調用新裝的SqlServer模塊,可以向后兼容。
Powershell模塊安裝
#https://www.powershellgallery.com
#在線下載安裝
Install-Module -Name Powershellget -force
#離線下載安裝
#https://www.powershellgallery.com/packages/CredentialsManager/1.1
#保存模塊
Save-Module -Name CredentialsManager -Path C:\powershellgallery
#拷貝到
%ProgramFiles%/WindowsPowershell/Module/
#加載即用、用時注冊
Import-Module -Name CredentialsManager
PowerShell 2.0 uses the appropriately-named Import-Module cmdlet to import modules. When this cmdlet is run, Windows PowerShell searches for the specified module within the directories specified in the PSModulePath variable. When the specified directory is found, Windows PowerShell searches for files in the following order: module manifest files (.psd1), script module files (.psm1), binary module files (.dll). For more information about adding directories to the search, see Modifying the PSModulePath Installation Path.
Beginning in Windows PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that this included in the value of the PSModulePath environment variable. If you do not save your module on a valid path however, you can still load them using the explicit Import-Module option, described above.
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。