Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Yet another simple array issue

64 views
Skip to first unread message

Ian_1

unread,
Feb 21, 2008, 10:32:01 AM2/21/08
to
Working
----------
$citrix="gccsm002","gccsm003"
Get-WmiObject Win32_Service -Filter "Name='alerter'" -computer $citrix| ft
SystemName,Name ,state -a

Not-Working
--------------
$citrix="server002","server003"
Get-WmiObject Win32_Service -Filter "Name='print spooler'" -computer
$citrix| ft SystemName,Name ,state -a


Anytime the service has multiple words, it just returs the PS> prompt. No
go. Why?

Marco Shaw [MVP]

unread,
Feb 21, 2008, 10:53:04 AM2/21/08
to

This just comes does to a difference between the "Name" and
"DisplayName" properties:

PS>gwmi win32_service
name displayname
---- -----------
...
Spooler Print Spooler

So, you're filtering on the name property, but using the value from
display name instead.

You need to do:
Get-WmiObject Win32_Service -Filter "DisplayName='print spooler'"...

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Marco Shaw [MVP]

unread,
Feb 21, 2008, 11:47:26 AM2/21/08
to
> Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005
> (E_ACCESSDENIED))

So this is a machine you've never connected to? It possibly has the
Windows Firewall enabled to block these remote calls.

Source: http://www.microsoft.com/technet/scriptcenter/resources/wmifaq.mspx

0x80070005 (DCOM ACCESS_DENIED)
This error occurs when the connected user is not recognized or is
restricted in some fashion by the remote server (for example, the user
might be locked out). This happens most often when accounts are in
different domains. Recent changes to WMI security can also cause this
error to occur:

• Blank passwords, formerly permitted, are not allowed in Windows XP and
Windows Server 2003.

• WMI does not allow asynchronous callbacks to a Windows 98 client. A
call like SWbemServices.ExecNotificationQueryAsync from a Windows 98
computer to a Windows XP computer will result in an Access Denied error
returned to the Windows 98 machine.

• The DCOM configuration access setting might have been changed.

• If the target computer is running Windows XP, the Forceguest value
under the registry key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa might be set to
force the Guest account off (value is zero).

Ian_1

unread,
Feb 21, 2008, 12:19:00 PM2/21/08
to
Ok how can I take the listing of several services off a server and display
them together?

IE Go from:
-----------------
PS C:\scripts> .\alerter.ps1

SystemName Name state
---------- ---- -----
GCCSM032 Dnscache Running
GCCSM033 Dnscache Running
GCCSM034 Dnscache Running
GCCSM035 Dnscache Running

SystemName Name state
---------- ---- -----
GCCSM032 Spooler Running
GCCSM033 Spooler Running
GCCSM034 Spooler Running
GCCSM035 Spooler Running

TO>
PS C:\scripts> .\alerter.ps1

SystemName Name state Name state
---------- ---- ----- -------- ------
GCCSM032 Spooler Running Dnscache Running
GCCSM033 Spooler Running Dnscache Running
GCCSM034 Spooler Running Dnscache Running
GCCSM035 Spooler Running Dnscache Running

Shay Levi

unread,
Feb 21, 2008, 12:50:04 PM2/21/08
to

You can use the OR operator inside the filter parameter:

Get-WmiObject Win32_Service -Filter "Name='alerter' or Name='W3SVC' or Name='Spooler'"
| ft SystemName,Name ,state -a


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> Ok how can I take the listing of several services off a server and
> display them together?
>
> IE Go from:
> -----------------
> PS C:\scripts> .\alerter.ps1
> SystemName Name state
> ---------- ---- -----
> GCCSM032 Dnscache Running
> GCCSM033 Dnscache Running
> GCCSM034 Dnscache Running
> GCCSM035 Dnscache Running
> SystemName Name state
> ---------- ---- -----
> GCCSM032 Spooler Running
> GCCSM033 Spooler Running
> GCCSM034 Spooler Running
> GCCSM035 Spooler Running

Shay Levi

unread,
Feb 21, 2008, 12:58:41 PM2/21/08
to

You can also use LIKE. This will get all service names that starts with 's':

Get-WmiObject Win32_Service -Filter "Name like 's%'"

Ian_1

unread,
Feb 21, 2008, 1:06:04 PM2/21/08
to
What about using multiple array's?

How to get this working?
---------------------------------------------------

$citrix=Get-Content C:\Scripts\servers1.txt
$services=Get-Content C:\Scripts\services.txt

get-wmiobject win32_service -filter "name='$services'" -computer $citrix |
ft SystemName,Name,state -a

Shay Levi

unread,
Feb 21, 2008, 2:30:56 PM2/21/08
to

I don't think you can. It's not a PowerShell issue. -Filter specifies a WQL
where clause to use as a filter.
The limitation is by WQL, it can filter with WQL standard keywords like 'AND',
'OR', 'LIKE' etc.

WQL (SQL for WMI)
http://msdn2.microsoft.com/en-us/library/aa394606(VS.85).aspx


-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com

> Im not looking for services with similar names, Im trying to get a
> specific list of services on a specific set of servers.
>
> See my double array question - stil open.
>


Brandon Shell [MVP]

unread,
Feb 21, 2008, 6:16:24 PM2/21/08
to
You could so something like this.. but I dont think this is what your really
looking for.
########################

$citrix=Get-Content C:\Scripts\servers1.txt
$services=Get-Content C:\Scripts\services.txt
foreach($server in $citrix)
{
foreach($service in $services)
{
get-wmiobject win32_service -filter "name='$service" -computer
$server
| ft SystemName,Name ,state -a
}
}
########################

Correct me if I am wrong.. arent you looking to have each server on one
line?

"Ian_1" <fake...@nodomain.com> wrote in message
news:9941B9A0-11A6-4417...@microsoft.com...
> OK so my script has evolved.
>
> Im trying to use 2 array's now, but trying to figure out how to make it
> work. Any suggestions?


>
> -------------------------------------------------
>
> $citrix=Get-Content C:\Scripts\servers1.txt
> $services=Get-Content C:\Scripts\services.txt
>
> get-wmiobject win32_service -filter "name='$services'" -computer

> CBR10606281
> | ft SystemName,Name ,state -a

Brandon Shell [MVP]

unread,
Feb 21, 2008, 10:33:31 PM2/21/08
to
See if this does what your looking for

###################################


$citrix=Get-Content C:\Scripts\servers1.txt
$services=Get-Content C:\Scripts\services.txt

foreach($computer in $citrix)
{
$myobj = "" | Select-Object Name
$myobj.Name = $computer
foreach($service in $services)
{
$result = Get-WmiObject Win32_Service -Filter
"Name='$service'" -computer $computer
$myobj | add-Member -MemberType NoteProperty -Name $Service -value
$result.state
}
$myobj |Format-Table *
}

"Ian_1" <fake...@nodomain.com> wrote in message

news:0D2CC01B-9296-4E98...@microsoft.com...

0 new messages