A technician is writing a simple PowerShell script to automate a routine maintenance task. Place the following script constructs in the correct order to initialize a path variable, evaluate whether the path exists, execute an automated action, and close the execution block.
- 1$LogPath = "C:\Logs\system.log"
- 2if (Test-Path $LogPath) {
- 3Remove-Item -Path $LogPath
- 4}
Answer
The proper sequence initializes the target variable ( LogPath) {), runs the file deletion command within the block (Remove-Item -Path $LogPath), and closes the control structure (}).
In standard procedural scripting logic, environment variables must be declared and assigned before they can be evaluated by control constructs such as conditional 'if' statements. Once the condition opens, nested tasks run within the block before the enclosing block is terminated.
Step-by-Step Solution
Key Concept
Execution sequence of basic scripting variables and conditional control constructs