Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

My company manufactures a medical instrument and the software that runs on it. Under the hood, it's got a PC running Windows 7. I'm developing a process so that untrained technicians can configure the system and install our applications.

I developed a set of PowerShell scripts and wrote a work instruction on how to use them. One of the scripts requires a restart of the computer. And the next script needs to be started manually after the technician logs back on (using a service account).

I want to simplify the process by registering the second script to run on user logon. I know that there are several mechanisms to do that

But, I'm looking for a mechanism that can be configured from PowerShell (adding and removing scripts is necessary). And preferably from a vanilla installation of Windows 7 and PowerShell. I don't have the ability to install the Group Policy PowerShell module, so that mechanism is out.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Using this article as a reference to start with, the following code will add user login script to the local user profile. Per the article, you may need to provide the whole path name to get the script to run on login.

$ComputerName = $env:COMPUTERNAME
$Computer = [adsi]"WinNT://$ComputerName"
$user = $Computer.psbase.Children.Find("SomeLocalUserName")
$user.LoginScript = "testscript.ps1"
$user.SetInfo()

Hope this helps.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.