Get service status from a remote server using powershell

How to get the service status for a remote computer that requires a username and password to log in?

I am trying to find a solution using the following code:

$serviceStatus = get-service -ComputerName $machineName -Name $service

The default syntax for the command is get-service:

Parameter Set: Default
Get-Service [[-Name] <String[]> ] [-ComputerName <String[]> ] [-DependentServices] [-Exclude <String[]> ] [-Include <String[]> ] [-RequiredServices] [ <CommonParameters>]

Parameter Set: DisplayName
Get-Service -DisplayName <String[]> [-ComputerName <String[]> ] [-DependentServices] [-Exclude <String[]> ] [-Include <String[]> ] [-RequiredServices] [ <CommonParameters>]

Parameter Set: InputObject
Get-Service [-ComputerName <String[]> ] [-DependentServices] [-Exclude <String[]> ] [-Include <String[]> ] [-InputObject <ServiceController[]> ] [-RequiredServices] [ <CommonParameters>]

It has no option for username and password.

+4
source share
2 answers

To my knowledge, Get-Service does not accept a credential parameter . However, you can do this through WMI :

$cred = get-Credential -credential <your domain user here>
Get-WMIObject Win32_Service -computer $computer -credential $cred

Update after comment:

securestring , . . .

+5

:

net use \\server\c$ $password /USER:$username
$service = Get-Service $serviceName -ComputerName $server

, .

+1

Source: https://habr.com/ru/post/1538952/


All Articles