A credential parameter is to allow you to run the function or cmdlet as a different user. Discover tips, examples, and best practices for securely managing credentials. Once the securestring object has been created the pscredential object can be created with the following syntax Discover the power of the powershell credential object This concise guide simplifies its creation and usage for secure scripting in no time. It needs an object of type pscredential
There are other ways, but they are a bit tricky because the password needs to be passed in as a securestring You can find how to programmatically build a pscredential object here Creates a new pscredential object from a given username and password Powershell commands use pscredential objects instead of username/password. Initializes a new instance of the pscredential class with a username and password This is an pscredential with both username and password initialized to null
The resulting credential object is returned as well as saved to disk or to azure keyvault so that it can be retrieved later. In my case i was creating a custom powershell cmdlet that takes a user name and password (as securestring)
WATCH