Whenever you need to enter credentials, you can either use Get-Credential or a low- level PS API function like so:
$c = $host.ui.PromptForCredential('Log on', $null, 'test\user', 'target')
$c
$c
You should nNote that the low- level function will allow you to set dialog captions and a custom message. For a custom message, you should replace $null with your message string.