Use a variable to pass computer list

Feb 24 at 10:52 PM
I've tried to use a variable to pass a list of computers I want processed. I have yet to have success.

$ServerList = "Server1,Server2,Server3"
.\Get-SQLServerInventoryToCLixml.ps1 -Computername $ServerList -LoggingPreference Verbose

When I look at the log file this is what I see:

Error resolving IP address for Server1,Server2,Server3: No such host is known

When I execute this .\Get-SQLServerInventoryToCLixml.ps1 -Computername Server1,Server2,Server3 -LoggingPreference Verbose all works as expected.

Any thoughts would be great.

Thank you

Feb 25 at 12:51 AM
You're close; PowerShell treats the entire list in quotes as a string. What you want is an array of strings. Try this:
$ServerList = @('Server1','Server2','Server3')
.\Get-SQLServerInventoryToCLixml.ps1 -Computername $ServerList -LoggingPreference Verbose 
Thanks for checking out SQL Power Doc!
Feb 25 at 4:21 PM

That did it. I should have guess that. Thank you for your help, and thank you for SQL Power Doc.

James M. Dorame

Database Systems Manager

Questar Assessment, Inc.

(952) 997-0755 (Office)

(952) 997-2700 (Fax)

Success by your Standards

CONFIDENTIALITY NOTICE: The information contained in this e-mail and any attachments may be confidential. If you are not an intended recipient, you are hereby notified that any dissemination, distribution, or copying of this e-mail is strictly prohibited. If you have received this e-mail in error, please notify the sender and permanently delete the e-mail and any attachments immediately. You should not retain, copy, or use this e-mail or any attachment for any purpose, nor disclose all or any part of the contents to any other person. Thank you. To reply to our email administrator directly, please send an email to [email removed].

Feb 27 at 9:19 AM
Edited Feb 27 at 9:20 AM
Hi Kendal

Busy testing SQL power doc and came across a weird error with the same method James mentions above.

First off this was the method behind the madness:

The requirement was for complete OU in AD to be included in the inventory, so I went with generating a comma delimited list from the servers in the OU with get-adcomputer and passing it to get-windowsinventorytoclixml.ps1 via a variable. Now it work like a charm until it hits server 142 of 158 then powershell stops responding.

My question is two fold, is there a better way for to collect the server from the OU and pass it to the script and if not what would your recommendation be given the current amount of servers in the OU that we would like to include in the inventory?

Server specs used for running the inventory
2 CPU's
10GB Memory

Thank you very much for SQL power doc and the amount of effort you put into this, it's much appreciated.

Mar 3 at 8:43 PM
Hi Willie,
One question and one answer for your twofold question!
1) When you hit server 142 of 158 and PowerShell stops responding do the logs show it's happening when verifying PING and WMI connectivity, or have you gotten past that point and getting held up on collecting information from an instance on that server?

2) Your best bet for targeting servers in a specific OU is to build the list of computer names ahead of time and pass that to the SQL Power Doc scripts. For example, here's how you can use the ActiveDirectory module to get a list of computers from an OU called "Production" in a domain called demo.local:
Import-Module -Name ActiveDirectory
$Computer = Get-ADComputer -SearchBase 'OU=Production,DC=demo,DC=local' -Filter 'ObjectClass -eq "computer"' | ForEach-Object {
Remove-Module -Name ActiveDirectory
From there you can pass $Computer to Get-SqlServerInventoryToClixml.ps1, e.g.:
.\Get-SqlServerInventoryToClixml.ps1 -ComputerName $Computer -LoggingPreference Verbose
Thanks for checking out SQL Power Doc!

Mar 13 at 7:48 AM
That's more or less the same idea I had, pushed the servers in the OU into an array and worked with them from there.

When PowerShell crashes the log just ends abruptly at:
2014-03-04 12:35:33.0220 $ [] Gathering Video Controller information
2014-03-04 12:35:33.1340 $ [] Gathering Startup Commands information
2014-03-04 12:35:33.3921 $ [] Gathering registry size information
2014-03-04 12:35:33.4281 $ [] Gathering information about services
The error occurs when the script starts doing the actual gathering of information after the "scanning on IP step". Seems that the size of the XML file that it generates in memory(My not so educated assumption) causes PowerShell ISE to crash. The weird bit though his that this happens at random, sometimes at the 100th server other times at the 120th server. It might be worth wile mentioning that I am using the "-additionaldata all" flag. So I am collecting a very large amount of data at the moment.

To try and get around this I approached it from another angle and submitted the server names in batches of 10, but to no avail.

Was still testing my script in the ISE though and once I did the same execution via the shell it worked like a charm.

So lesson learned, dev work on ISE and heavy lifting in die shell.

Mar 14 at 1:54 PM
Yes, good call - the console has less overhead than the ISE. Are you running a SQL Server Inventory or just a Windows Inventory? Also, PowerShell 3.0 offers significant improvements with custom objects (which SQL Power Doc uses heavily) over PowerShell 2.0, so if you can make sure to use PoSh v3 or higher.