I have an API method like this
[HttpGet]
public string UpdateComputerDescriptions()
{
var cred = System.Net.CredentialCache.DefaultCredentials;
UpdateDescriptionsAndTimestamp(System.Net.CredentialCache.DefaultNetworkCredentials);
return "done";
}
And I've tried to call it from PowerShell with
$webclient = new-object System.Net.WebClient
$webclient.Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)
$webpage = $webclient.DownloadString($url)
And
Invoke-WebRequest $url -Credential $creds
My problem is that I need to pass the $creds
credentials to my UpdateDescrptionsAndTimestamp
method.
However, when I check DefaultCredentials
and DefaultNetworkCredentials
objects in the API method, they don't contain any values (I'm expecting to see at least the username in there).
I even tried changing the signature to public string UpdateComputerDescriptions(NetworkCredential credential)
and calling with
Invoke-WebRequest $url -Body @{credential=$creds} -Credential $creds
But I get the same result.
How can I achieve this?
Note I do not want to pass in plain text (or - for that matter - encrypted) credentials, as the powershell script will eventually be run as the user and I'll just pass in the default credentials. I just need to know how I can retrieve this from inside the API