Function from cmd line - specify diff creds?

Welcome Forums General PowerShell Q&A Function from cmd line - specify diff creds?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
5 years, 6 months ago.

  • Author
    Posts
  • #12919

    Participant
    Topics: 20
    Replies: 25
    Points: 0
    Rank: Member

    I am trying to use a function and I'm running it from a command line. I want to have the option to enter different credentials as I have to run it against domain and non-domain systems, as well as systems in other domains.

    The function doesn't have anything in place to prompt, is it possible to add something easily that would do this either on the command line or in the function?

    The function command line I'm using is:

    gc = c:\temp\computers.txt | get-stuff | export-csv c:\temp\test.csv

  • #12934

    Participant
    Topics: 0
    Replies: 669
    Points: 0
    Rank: Member

    A powershell credential is of type System.Management.Automation.PSCredential so your function needs to be able to generate a credential using that type.

    Do you want to generate a new credential for every computer that comes down the pipeline or can you use a the same one?

  • #12935

    Participant
    Topics: 20
    Replies: 25
    Points: 0
    Rank: Member

    I can use the same one, in an "ideal" world, I'd like to get prompted if it hits a server that I don't have access to.

The topic ‘Function from cmd line - specify diff creds?’ is closed to new replies.