It’s not a best practice to manage permissions with a function wrapper, the permissions should be managed on the endpoint where you accessing folder permissions. To provide an example, you would need to do a ValidateScript to parse out the username from the Credential object.
function Test-It {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $True)]
[ValidateScript({
if ('MyUserName','YourUserName' -contains $_.UserName) {
$True
} else {
Throw [System.UnauthorizedAccessException] ("The user {0} is not authorized." -f $_.UserName)
}
})]
[PSCredential]$Credential
)
begin{}
process{'Processing user {0}' -f $Credential.UserName}
end{}
}
Test-It -Credential $creds