$query = " select @@servername" $csvFilePath = "c:\Scripts
$query = " select @@servername"
$csvFilePath = "c:\Scripts\queryresults.csv"
$instanceNameList = get-content c:\Scripts\serverlist.txt
$results=@()
foreach($instanceName in $instanceNameList)
{
write-host "Executing query against server: " $instanceName
$results += Invoke-sqlcmd -Query $query -ServerInstance $instanceName
}
# Output to CSV
write-host "Saving Query Results in CSV fORMat..."
$results | export-csv $csvFilePath -NoTypeInformation
--结束END--
本文标题: Powershell连接多服务器执行SQL脚本
本文链接: https://lsjlt.com/news/36843.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0