1
1bruce
Guest
I have the following powershell script:
#########################
$namespaces = @(gwmi -ns 'root\Microsoft\SqlServer' __NAMESPACE | ? {$_.name -match 'ComputerManagement' } | select name).Name
foreach($space in $namespaces) {
$wmi = $null
$instance = Get-WmiObject -Namespace ("root\Microsoft\SqlServer\" + $space) -Class ServerSettings
$wmi = Get-WmiObject -Namespace ("root\Microsoft\SqlServer\" + $space) -Class SqlService
if ($wmi -eq $null) {
Write-Output "not found"
}
else {
$wmi | Format-Table -Property Hostname, DisplayName, ServiceName, StartName, @{name="InstanceName"; exp={$instance.InstanceName}} -AutoSize | Out-String -Width 4096 | Out-File -FilePath "\\server_name\file_path.csv"
}
}
############################
After running on a single server, the result is correct (table format):
Hostname DisplayName ServiceName StartName InstanceName
When I distribute a script using SCCM "Software Library -> Scripts" for a collection with 16 clients, I only get a result for one of the clients (randomly selected).
I need to create a script so that the result obtained includes all clients in a given collection and is saved to the csv file.
#########################
$namespaces = @(gwmi -ns 'root\Microsoft\SqlServer' __NAMESPACE | ? {$_.name -match 'ComputerManagement' } | select name).Name
foreach($space in $namespaces) {
$wmi = $null
$instance = Get-WmiObject -Namespace ("root\Microsoft\SqlServer\" + $space) -Class ServerSettings
$wmi = Get-WmiObject -Namespace ("root\Microsoft\SqlServer\" + $space) -Class SqlService
if ($wmi -eq $null) {
Write-Output "not found"
}
else {
$wmi | Format-Table -Property Hostname, DisplayName, ServiceName, StartName, @{name="InstanceName"; exp={$instance.InstanceName}} -AutoSize | Out-String -Width 4096 | Out-File -FilePath "\\server_name\file_path.csv"
}
}
############################
After running on a single server, the result is correct (table format):
Hostname DisplayName ServiceName StartName InstanceName
When I distribute a script using SCCM "Software Library -> Scripts" for a collection with 16 clients, I only get a result for one of the clients (randomly selected).
I need to create a script so that the result obtained includes all clients in a given collection and is saved to the csv file.