我想在200多种不同的服务器上获取所有已安装的SQL版本值。
计划是在ServerListSQLVersions.txt中具有所有服务器名称 并将所有SQL版本导入CSV。
$Username = ''
$Password = ''
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString = $pass
# Users you password securly
$MySecureCreds = New-Object -TypeName
System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString
$Array = @()
##Create a Folder called SQLVersions##
$scriptPath = "C:\Transfer to SV000229\SQL Script"
$server = Get-Content "$scriptPath\ServerListSQLVersions.txt"
$wmiobj = Get-WmiObject -class Win32_product | where Name -like '*SQL*' | Select-Object name,version
function getWMIObject($server, $wmiobj, $MySecureCreds) {
$result = Get-WmiObject $wmiobj -ComputerName $server -Credential $MySecureCreds
#Write-Host "Result: "$result
$Array+= $Result
}
$Array = Export-Csv $scriptpath\output.csv -NoTypeInformation
我在CSV中的输出是:
长度
0
答案 0 :(得分:0)
我用了
foreach($ computers在$ computers中){
代替功能并手动提供信息。
输出也无法导出,因为我使用了=而不是|
现在工作。