0

In Windows 7 Prof, executing in Windows Powershell_ISE (as administrator) the Powershell (ver. 3) commands produces expected result (of adding a domain user to local/machine Administrators group) but launching it from a script .ps1 file in folder C:\Users\myDomainUser\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup does not !?

$objGroup = [ADSI]("WinNT://myComputerName/Администраторы")'Administrators in Russian
$objUser = [ADSI]("WinNT://myDomainName/myDomainUser")
$objGroup.PSBase.Invoke("Add", $objUser.PSBase.Path)

Why?
How to better add a domain user to local administrators group on Windows 7 reboot?

2 Answers 2

2

For security reasons, (and in addition to the script execution policy thing) Microsoft has set .ps1 files to open using notepad. (Silly Microsoft.) Scheduled tasks may be a better solution, but if you want to launch the script from the startup folder I would recommend placing a shortcut to the script in startup and store the script somewhere else. I use shortcuts that look something like this: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "C:\Scripts\Powershell\Tool.ps1"

If you use this syntax, note that any additional options you might want to pass to powershell must go before the -file option. Anything after the -file is interpreted as either the path to the script or an option/argument to be passed to the script.

1

You may want to try running it using the task scheduler.

Start the task scheduler (start menu, all programs, accessories, system tools, task scheduler). In the right panel, select "create task". Enter a name for the task. Change the user if you want. Select "run with highest privileges." In the triggers tab, create a trigger for "at logon" or "on startup" depending on what you want. In the actions tab, create a new action that points to the script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .