[英]How Can I Make My Powershell Get-WMIObject Script Faster Cycling Through Servers
[英]Get the SQL Versions of all servers with get-wmiobject
我想在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
我用了
foreach($ computers在$ computers中){
而不是功能,而是手動提供信息。
另外,輸出也無法導出,因為我使用了=而不是| |。
現在可以使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.