I am modifying our corporate image using a PowerShell script named InstallScript. I prefer to open that InstallScript with the ISE after I login and watch it execute in order to follow any error messages, etc.
I assume its possible to login to a machine and have the ISE open with a script (,\InstallScript.ps1) already loaded in the script editor.
I thought I could do this with a Scheduled Job that would trigger upon user login;, however, I keep getting hung up. When I log on to a machine, I never see the PowerShell ISE; the TaskScheduler reports the Job ran successfully.
#Prepare the machine for use on the next logon from this person
Get-ScheduledJob | Where-Object { $_.Name -match ‘LogonScript’ } | Unregister-ScheduledJob
[scriptblock]$scriptblock = { "Start-Process PowerShell_ISE.exe -Verb RunAs -ArgumentList ‘C:\Install\InstallScript.ps1’ " }
$SchedJobProps = @{}
$SchedJobProps.ScriptBlock = $scriptblock
$SchedJobProps.Name = ‘LogonScript’
$SchedJobProps.Trigger = ( New-JobTrigger -AtLogOn -User $env:USERNAME )
$SchedJobProps.ScheduledJobOption = ( New-ScheduledJobOption -RequireNetwork -WakeToRun -MultipleInstancePolicy “IgnoreNew” -RunElevated )
$SchedJobProps
Register-ScheduledJob @SchedJobProps