Quantcast
Channel: /r/powershell – How to Code .NET
Viewing all articles
Browse latest Browse all 8793

Need to run a script as a different user. but how?

$
0
0

Hello there! I’m currently working on a CI/CD pipeline for our TFS-enviroment.

I’m totally new with this, since i’m an apprentice in a other department and got the chance to have a look into our developer-team.

My target is to start a new lab build, which restores a machine to a given snapshot and then installes software and features with PowerShell (+DSC), then installs our software and after that tests it. So, most of my scripts do work (surprisingly) but i’ve got stuck at one point. After installing AppFabric I want to configure it. To archive this I need to run a script as a different user. But this wont work.

$username = "domainuser" $password = "passwordinplaintext" $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force)) $arguments = "-file 'C:CICDscriptsConfigureAppFabric.ps1'", "-Verb runAs" Start-Process powershell.exe -Credential ($credentials) -NoNewWindow -ArgumentList $arguments 

as you can see, i want to run the “ConfigureAppFabric.ps1” as the user “domainuser”. If i run the script a PS window pops up and closes instantly again. This happens, if i run this manually. If I let the TFS run the script after all other prerequsites are installed it gives me this:

Start-Process : This command cannot be run due to the error: Access is denied. At C:CICDscriptsRunAs.ps1:7 char:1 + Start-Process powershell.exe -Credential ($credentials) -NoNewWindow -ArgumentLi … + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

which seems strange. The User has all rights to create new databases on my SQL-Server etc.

I’m lost. Is it a mistake in my PS-script?

Thanks!

submitted by /u/Eduhsoj
[link] [comments]

The post Need to run a script as a different user. but how? appeared first on How to Code .NET.


Viewing all articles
Browse latest Browse all 8793

Trending Articles