How to get the service status for a remote computer that needs a user name 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 get-service
command is:
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>]
This does not have an option for username and password.
Use PowerShell to Check Service Status on a Remote Computer You can use the Get-Service cmdlet to get the status of services not only on the local but also on remote computers. To do this, use the –ComputerName parameter. You can use the NetBIOS, FQDN name, or an IP address as a computer name.
Summary of Create Get-ServiceStatus Function The purpose of this PowerShell function is to filter the Windows services, so that you can see which are running, and which are 'Stopped'.
Using the Get-Service PowerShell cmdlet, you can generate a list of Windows Services running on your Windows 10/8/7 computer. Open an elevated PowerShell console, type Get-Service and hit Enter. You will see a list of all the Services installed on your Windows system.
As far as I know, Get-Service doesn't accept a credential parameter. However, you can do it through WMI:
$cred = get-Credential -credential <your domain user here>
Get-WMIObject Win32_Service -computer $computer -credential $cred
Update after comment:
You can save credentials as a securestring into a file, and then reload it for manually creating a credential without having a prompt. See information here.
This also works:
net use \\server\c$ $password /USER:$username
$service = Get-Service $serviceName -ComputerName $server
Note that password should not be in a secure string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With