I have a .ps1 script that I need to launch in Powershell v2.0. Because of this, I use a shortcut file to launch it in Sta mode:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -Sta -File "C:\TestFile.ps1"
This launches Powershell in Sta mode and the file is able to run. However, this PowerShell script uses New-ADUser and runs into Access Denied issues when trying to add the user. From what I can tell, this is due to needing to run PS in Administrator mode. However, I'm having trouble launching it in both Admin and -Sta mode at runtime, and I'm not really sure what to do.
Is there a way I can use the shortcut to launch Powershell as administrator AND -Sta?
New-ADUser
needs to run using the credentials of a user with permissions to add users in AD. Running it as (local) Administrator should not help you there.. – Theo