v1.0.0.0
.SYNOPSIS
Script to process custom configuration steps in specified order for a server
.DESCRIPTION
1. This script uses an array to define the order of user provided functions to process.
2. It uses 2 variables to control the flow of user provided functions.
$Script:SetJSON.Tracking.ExitCode
$Script:SetJSON.Tracking.ProcessReboot
3. There are 4 script parameters. None are mandatory.
AutoLoginUser
AutoLoginPassword
DomainUser
DomainPassword
Domain
4. There are also 2 regions that must remain as written.
#region begin MUST HAVE PROCESS LOOP
#region begin MUST HAVE FUNCTIONS
5. The 3rd region, #region begin USER FUNCTIONS, is for user provided functions.
6. Files Written to the hard drive are:
AutoConfig_Tracking.json : The script uses this to track its progress
AutoConfig_Tracking_Log.txt : This the human readable log with step results and time stamps.
These are written to the same location as where the script was ran.
.EXAMPLE
This is a sample of the control array that includes the built-in 'Restart-Server' function:
$Steps = @(
[ORDERED]@{'Action' = 'CheckUpdates'; 'Status' = 'NotStarted' ; 'TimeStamp' = '00/00/00' ; 'Function' = 'Get-PendingUpdates' }
[ORDERED]@{'Action' = 'UpdatesReboot'; 'Status' = 'NotStarted' ; 'TimeStamp' = '00/00/00' ; 'Function' = 'Restart-Server' }
)
The only thing you need to define is the 'Action' name and the 'Function' to call.
How the Action/Function completes is controlled by your use of the following variable in your function.
You can set the a function ExitCode to what you want, BUT, the script uses these three:
$Script:SetJSON.Tracking.ExitCode = 0 : This tells the script to mark that step as completed and to continue processing
$Script:SetJSON.Tracking.ExitCode = 1 : This tells the script to mark that step as Failed/Exit and halts the script
$Script:SetJSON.Tracking.ExitCode = 2 : This tells the script to mark that step as Failed/Continued and to continue processing
If you include the use of the built-in 'Restart-Server' function, you can also define in your function whether or not
to process the reboot depending on the outcome of your function. This is separate from the ExitCode.
If you call the 'Restart-Server' function after one of yours, the following MUST be set or the script will halt.
$Script:SetJSON.Tracking.ProcessReboot = "False" or
$Script:SetJSON.Tracking.ProcessReboot = "True"
So using the above sample array, here are some examples of how the 'Get-PendingUpdates' and 'Restart-Server' could flow based on your use of
$Script:SetJSON.Tracking.ExitCode
$Script:SetJSON.Tracking.ProcessReboot
1. 'Get-PendingUpdates' fails due to no communications with update server.
You could set the ExitCode to '$Script:SetJSON.Tracking.ExitCode = 1' for that result so the script halts so you can check the communication issue.
$Script:SetJSON.Tracking.ProcessReboot is not needed because the script will have quit.
2. 'Get-PendingUpdates' fails due to any reason, but you don't consider it a hard stop.
You could set the ExitCode to '$Script:SetJSON.Tracking.ExitCode = 2' for that result so the rest of steps continue to process.
Because the 'Restart-Server' follows 'Get-PendingUpdates', you have to set $Script:SetJSON.Tracking.ProcessReboot.
You can set '$Script:SetJSON.Tracking.ProcessReboot = "False"' for this failure so the unneeded reboot isn't processed.
3. 'Get-PendingUpdates' performs as designed so you can set the two variables as such so the server reboots and continues processing steps.
$Script:SetJSON.Tracking.ExitCode = 0
$Script:SetJSON.Tracking.ProcessReboot = "True"
4. You can supply -DomainUser, -DomainPassword, and -Domain at the command line that will create a System.Management.Automation.PSCredential
object that can be used in a domain join.
If either parameter is not supplied, $DomainCredentials will be forces to $null.
You can then check for $null in your domain join function to determine whether to process or not.
.PARAMETERS
AutoLoginUser : Used to auto-login and continue running the script via the registry
AutoLoginPassword : Used to auto-login and continue running the script via the registry
DomainUser : Separate credentials to perform a domain join.
DomainPassword : Separate credentials to perform a domain join.
Domain : Domain to pass to your domain join function if you have one