Link to home
Start Free TrialLog in
Avatar of MartynLawson
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.PSCredenti
   al:String) [Get-Service], ServiceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
   Commands.GetServiceCommand

Does anyone know where I am going wrong with this?



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 MartynLawson
MartynLawson

ASKER

Thanks for that! I didn't realise that I couldn't specify credentials with certain commands.