3

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.

Anthony Mastrean
  • 441
  • 1
  • 6
  • 18

1 Answers1

2

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.

Christopher
  • 1,673
  • 12
  • 17