The Group Policy system in Windows stores startup and shutdown scripts under the registry keys HKLM:\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Startup and HKLM:\SOFTWARE\Policies\Microsoft\Windows\System\Scripts\Shutdown. Each key has a subkey for each group policy object that applies. Each of those child keys has another level of keys that correspond to individual scripts that apply to the machine.
Example 242 allows you to easily retrieve and access the startup and shutdown scripts for a machine.
Example 242. GetMachineStartupShutdownScript.ps1
############################################################################## ## ## GetMachineStartupShutdownScript.ps1 ## ## Get the startup or shutdown scripts assigned to a machine ## ## ie: ## ## PS >GetMachineStartupShutdownScript Startup ## ##############################################################################
param( $scriptType = $(throw "Please specify the script type") )
## Verify that they've specified a correct script type $scriptOptions = "Startup","Shutdown" if($scriptOptions notcontains $scriptType) {
$error = "Cannot convert value {0} to a script type. " + "Specify one of the following values and try again. " + "The possible values are ""{1}""."
$ofs = ", " throw ($error f $scriptType, ([string] $scriptOptions)) }
## Store the location of the group policy scripts for the machine $registryKey = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\System\Scripts"
Example 242. GetMachineStartupShutdownScript.ps1 (continued)
## Go through each of the policies in the specified key foreach($policy in GetChildItem $registryKey\$scriptType) {
## For each of the scripts in that policy, get its script name ## and parameters foreach($script in GetChildItem $policy.PsPath) {
GetItemProperty $script.PsPath | Select Script,Parameters } }