To test a web application, quite often we need to log on in different user roles. Many years ago I created a shortcut to do the work, with help of some third-part tool. But, to keep the environment simple, is there a way to do that directly?
It's not as easy as it looks like.
At first, I tried the DOS command "runas". It doesn't work for IE.
Then, I tried "Task Scheduler". Not easy to let the task program open in current desktop window.
The last one: PowerShell script.
Save the scripts below to a PowerShell script file "RunIEasTestUser1.ps1", then right click the file, select "Run with PowerShell" from the context menu.
$username = "DomainName\TestUserLogin1"
$password = "somepassword" | ConvertTo-SecureString -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -Credential $cred -passthru -LoadUserProfile -ArgumentList "http://testserver"