Link to home
Start Free TrialLog in
Avatar of Kelly Garcia
Kelly GarciaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Quest Powershell code

Hi All,

I have written the code below however it does not work. please can someone explain why it doesn't work as I am trying to advance in powershell.

Get-QADComputer | Get-Service -ComputerName $_.computername -Name *xagt*

Open in new window

Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Is ComputerName a property returned by Get-QADComputer? It's been years since I've seen Quest, so it could be...
Get-QADComputer | Get-Service -Name *xagt*

Open in new window

The value is picked out because ComputerName accepts pipeline input:
PS> Get-Help Get-Service -Parameter ComputerName

ComputerName <String[]>
...
    Required?                    false
    Position?                    named
    Default value                None
    Accept pipeline input?       True (ByPropertyName)
    Accept wildcard characters?  false

Open in new window

The "ByPropertyName" means the input object (returned by Get-QADComputer) must have a property with a corresponding name. If it does, the parameter will automatically fill itself in.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kelly Garcia

ASKER

Hi Qlemo,

I have tried this however I get the following error:

Get-Service : Cannot open Service Control Manager on computer 'LP-LON-1573$'. This operation might require other
privileges.
At line:1 char:31
+ ... p-lon-1573 | Get-Service -ComputerName {$_.computername} -Name *xagt*
+                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Service], InvalidOperationException
    + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

Regards,
Kay
That's your access rights, not code.
... and should be the same when using Chris' code.
the account has domain admin rights and also this my own laptop, the lp-lon-1573 and I am clearly added as a admin on it
Something else perhaps. But it's not the code. You might work around it, for example by using remoting instead of RPC.
Invoke-Command { Get-Service *xagt* } -ComputerName lp-lon-1573

Open in new window

WMI is open as yet another option, uses DCOM over RPC, but a different permissions model.