MartynLawson
asked on
Error calling credentials in Powershell Script
I'm trying to create a Powershell script that retrieves a server name from a text file and then performs the get-service command on the server name and outputs the results to a file. The script that I am using is as follows
$computernames = Source location of the computer names
$credentials = get-credentials "domain account name"
get-service -computername $computernames $credential | where-object {$_.Status -eq "Running"} | export-csv C:\Users\Output.csv.
When I run this command I get the following error:-
Get-Service : Cannot find any service with service name 'System.Management.Auto
mation.PSCredential'.
At line:1 char:12
+ get-service <<<< -computername $computernames $credential | where-object {$_
.Status -eq "Running"} | export-csv C:\Users\Output.csv
+ CategoryInfo : ObjectNotFound: (System.Manageme...on.PSCr edenti
al:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName ,Microsoft .PowerShel l.
Commands.GetServiceCommand
Does anyone know where I am going wrong with this?
$computernames = Source location of the computer names
$credentials = get-credentials "domain account name"
get-service -computername $computernames $credential | where-object {$_.Status -eq "Running"} | export-csv C:\Users\Output.csv.
When I run this command I get the following error:-
Get-Service : Cannot find any service with service name 'System.Management.Auto
mation.PSCredential'.
At line:1 char:12
+ get-service <<<< -computername $computernames $credential | where-object {$_
.Status -eq "Running"} | export-csv C:\Users\Output.csv
+ CategoryInfo : ObjectNotFound: (System.Manageme...on.PSCr
al:String) [Get-Service], ServiceCommandException
+ FullyQualifiedErrorId : NoServiceFoundForGivenName
Commands.GetServiceCommand
Does anyone know where I am going wrong with this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER