我写这个是为了在远程sql服务器上获取已安装实例的列表,但它失败了以下错误我将按如下方式实现此目的
# -- Get the patch servers from central server function
get-patchservers {
# -- Where is your central patching database located?
$sql_inst = Read-Host "SQL instance hosting Patching DB; default: Severname\SQL201201"
# -- Default patching control server to "ServerName\SQL201201"
if($sql_inst -eq "") {$sql_inst="Severname\SQL201201"}
# -- What's the name of your central patching database?
$sql_db = Read-Host "Name of Patching DB; default:patchdb"
# -- Default datatabase for patching db
if($sql_db -eq "") {$sql_db="patchdb" }
# -- T-SQL to feacth server name from cerntral db
$Tsql = "SELECT svr_name FROM server"
$ServerList = Invoke-Sqlcmd -Query $Tsql -ServerInstance $sql_inst -Database $sql_db #return $ServerList
foreach($Server in $ServerList) {
ECHO $Server
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Server)
$regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\MicrosoftSQL Server\\Instance Names\\SQL" )
$instances = $regkey.GetValueNames()
$instances
}
}
答案 0 :(得分:0)
我发现了这里造成的问题。它看起来与invoke-sqlcmd命令返回的标头有问题