2

Alright, I've tried to figure this out, but figured it's time to ask the interwebs. I'm wondering if this is a bug or what.

I'm trying to start jobs against multiple computers to determine which database names reside on them.

My Computer1 system setup is: Powershell 2.0, Windows 2k3 Enterprise x64

On Computer1 I can run:

Start-Job -scriptblock {gwmi -query "select * from win32_computersystem" -ComputerName "Computer2"}

And the job will be stuck in a state of "Running" forever. But not if I run the same command outside the job's script block in the shell.

I've tried this exact setup here with a local admin's (vs my domain) credentials, but same result. It doesn't work for me for some reason.

I've tried building a custom WMI dotnet object that doesn't use gwmi, but I get the same result!

The -asjob parameter?: This is not a solution.

  1. When using this parameter, the powershell window crashes at around 2GB memory used on a 12GB system; Whereas I can use start-job all the way to 12GB without problems. I might as well run every query in serial fashion.

  2. Also, memory is never reclaimed when using the -Asjob parameter on Gwmi, so no further jobs can continue; even after running "remove-job * -force" or "[GC]::Collect()", the memory consumption for powershell.exe stubbornly remains the same (again, unlike start-job).

  3. Since SQL instance names vary, the wmi class names vary. So I need to run multiple query commands against multiple classes. While is technically doable, its more complex and, given the above memory requirements, limited to 2gb. I'm hoping someone will just know how to make start-job work like it should.

So about the only thing I haven't tried is maybe I have to specify the authority parameter?

Community
  • 1
  • 1
Tom
  • 21
  • 1
  • 3
  • `Start-Job` is for running background jobs _locally_. I guess you mean (and actually use) `Invoke-Command` in your code example above? – Torbjörn Bergstedt Jul 20 '11 at 09:28
  • 1
    Thanks for the comment. No, I don't mean invoke-command. Most of the computers I'm scanning don't have WinRM enabled, but they do have WMI enabled. I want to do a WMI query against a remote computer. – Tom Jul 20 '11 at 16:51
  • I tried your example and the job completed successfully. – JasonMArcher Jul 21 '11 at 23:00

1 Answers1

0

I use Invoke-Command -asJob for this :

PS C:\> Invoke-Command -ComputerName "WM2008R2ENT" -ScriptBlock {gwmi -query "select * from win32_computesystem"} -AsJob

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Running    True            wm2008r2ent          gwmi -query "select * ...


PS C:\> Get-Job

Id              Name            State      HasMoreData     Location             Command
--              ----            -----      -----------     --------             -------
1               Job1            Completed  True            wm2008r2ent          gwmi -query "select * ...


PS C:\Développements> Receive-Job 1


Domain              : dom.fr
Manufacturer        : VMware, Inc.
Model               : VMware Virtual Platform
Name                : WM2008R2ENT
PrimaryOwnerName    : Utilisateur Windows
TotalPhysicalMemory : 683139072
PSComputerName      : wm2008r2ent

You can replace the machine name by a list of machines. Don't try to code again '-Computername in the CmdLets you are using in the script block.


(Edited) I try you command line and it works for me from a client Windows Seven (64 Bits) to a W2K3 (32 bits)

My client is NOT in the domain of the server and I use domain admin credentials.

Have you made the test from a 32Bit Powershell or a 64 Bits Powershell ?

Do you try to stop WMI service on remote machine and clean the WMI database, it's sometime suitable when you made too much tests on a WMI server (with events for example).

JPBlanc
  • 70,406
  • 17
  • 130
  • 175
  • Thanks for the comment. Most of the computers I'm scanning don't have WinRM enabled, but they do have WMI enabled. I want to do a WMI query against a remote computer. – Tom Jul 20 '11 at 16:51
  • Well, I tested the above code on a 2008 x64 system and it's working. Unfortunately, I really need to have things working on my 2003 x64 box :( – Tom Jul 20 '11 at 17:44
  • You can Install the Powershell V2 package on it, you'll have WinRM service. – JPBlanc Jul 20 '11 at 19:22
  • Thanks for the suggestion, but we're talking about 1300+ machines to install that service on. I'm going to shoot for finding a 2008 box to use for now unless anyone else can suggest a fix. – Tom Jul 20 '11 at 20:12
  • I test Your script line in my context (client : Windows Seven 64 bits, server W2K3 R2 32 bits) and it works. You may have some trouble on your WMI service on remote computer, I edit my answer this way. – JPBlanc Jul 21 '11 at 03:32
  • JPBlanc, that is not a good test. You need to test a W2k3 Enterprise 64bits as the client. If the remote WMI service was the problem then the command would also fail when I run it outside of a job. – Tom Jul 22 '11 at 19:48