I can't imagine anyone actually thinking that this would be the right thing to do. This is just a simulation where I'm using a dummy account on a test server and was tired of typing the pwd. The code above is what I used and modified from the following article: $M圜ommand = 'Invoke-Sqlcmd -query ''SELECT ServerProperty('ComputerNamePhysicalNetBIOS')'' -ServerInstance ''SQLInstance'' -Database ''DatabaseName''' #$PlainPassword = $Credentials.GetNetworkCredential().Password $MyDomain = $Credentials.GetNetworkCredential().Domain $MyUserName = $Credentials.GetNetworkCredential().UserName $Credentials = New-Object -ArgumentList $UserName, $SecurePassword $SecurePassword = $PlainPassword | ConvertTo-SecureString -AsPlainText -Force I would like to be able to spawn the new process as a different user and pass some sql commands to it. The following code seems to work for running the new process as the different user, but I cannot understand how to send a command to the new process.
I'm trying to create a PowerShell script that will run a new PowerShell Process as a different 'Windows' user.