Credential in Invoke-Command

I am using an invoke command to pull out the WSUS service from list of server. However, for 1 server I need to use a different credential. Wondering how I can get this accomplished.

sample as below:-

Input file

import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + ‘\ConfigurationManager.psd1’)
Import-Module ActiveDirectory

Set-Location ABC:

$computername=(Get-CMSite).ServerName

foreach ($C in $computername)
{
$userdata = (Invoke-Command -ComputerName $c -ScriptBlock {Get-service WsusService| select displayname, Status| sort-Object Status})

You would use the -Credential parameter of Invoke-Command.

Since you have a foreach loop that iterates through the list of computers, something like this perhaps:

#creds for separate server
$creds = Get-Credential -Credential "domain\username"

foreach ($C in $computername)
{
    if ($c -match "name of server with own credentials")
    {
       Invoke-Command -Credential $creds
    }
    else
    {
        Invoke-Command
    }
}

Thanks Richard, but will this prompt for the password. I need to set this as Schedule task. I know, I am asking very basic thing here, but trying to get the hold of it.