PSM: Hardening script fails with Write-Log is not recognized and $StepUnitStatusTracker errors
Symptom
Running the PSM hardening script (PSMHardening.ps1) fails with one or more of the following errors:
The variable '$StepUnitStatusTracker' cannot be retrieved because it has not been set.
write-log : The term 'write-log' is not recognized as the name of a cmdlet, function, script file, or operable program.
Environment
14.6 Privilege Cloud Privilege Cloud PSM
Cause
The PSM hardening script loads required modules and functions at an early stage using using module and dot-sourcing.
If the PowerShell session is affected by:
-
User or system PowerShell profiles
-
StrictMode configuration
-
Custom PowerShell environment settings
the module initialization may fail before logging functions and internal variables are created. As a result, secondary errors such as missing Write-Log and $StepUnitStatusTracker are reported.
This issue may occur even when:
-
Execution Policy is set to Unrestricted
-
Required files exist in the correct directories
-
File system permissions are correct
Resolution
Run the PSM hardening script from a clean PowerShell session without loading any profiles.
Steps
-
Open Windows PowerShell as Administrator.
-
Execute the following command: powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "cd 'C:\Program Files (x86)\CyberArk\PSM\Hardening'; .\PSMHardening.ps1"
This launches a PowerShell session that bypasses profile loading and execution policy checks for the duration of the script, allowing all required modules and functions to load correctly.