Overview
This article will list some of the best practices that should be used to configure and make LCT work for Windows scripts. It will also be used as a troubleshooting guide to help resolve some common issues.
Best Practices
General
Turn off Blocking on the Script Definition while testing
Please refer to this link for more detail: SovLabs - Add Lifecycle Script Definition
This will cause the workflow to not initiate a destroy on failure. Or, the other option is to test your script on a Specific Host instead of on the Provisioned Node.
Enable blocking only if a failure in the script means that you want to cancel your build process
Use descriptive logging in your custom scripts at key points so failures are clear.
Example(s): Write-Host, Write-Transcript, etc.
More information on these commands is listed below in the PowerShell Commands section
Re-execute failed workflow runs from vRealize Orchestrator for testing
Requires Blocking to be disabled, or execution against Specific Host
See additional details below in the Advanced Troubleshooting section for more information
Monitor the scripts directory for the script to copy and verify that the service account has the appropriate permissions on the server/endpoint
Add Service Account to Local Administrators group for testing purposes
The default script directory in your Script Definition can/should be updated to avoid possible UAC/GPO Issues
Example: Change directory from C:\Windows\Temp to C:\SovLabs
Test you script locally on a server to verify it works
Include logic and output in your scripts to check for successful execution
Set exit codes based on expected results
- Exit code of 0 usually means success for PowerShell
- Microsoft - Windows Powershell Exit Codes
Script Definition
Include the EBS state and script priority in the script name 1190_10_Install Apache
Also helpful to include VC Name and OS for script in name 1190_10_VC01_CENT_Install_Apache
Make sure to set the order for the scripts to be run if in if you have multiple script definitions using the same EBS subscription
An alternative way of doing it would be to have each Script Definition going to it's own EBS subscription (This may make it easier for troubleshooting)
Template Preparation
- Allow PowerShell to open in Admin mode by default
If you're using a new default directory for your scripts, you may want to create the new folder in your template so it's on every new VM
Prep the template to allow service account to execute powershell scripts
Add Service Account to Local Administrators group for testing purposes
Disable automatic VM Tools Upgrade (optional)
Link to VMware article is posted below. This is set on the Host(s) level
PowerShell Commands
Start-Process - The Start-Process cmdlet starts one or more processes on the local computer. To specify the program that runs in the process, enter an executable file or script file, or a file that can be opened by using a program on the computer. If you specify a non-executable file, Start-Process starts the program that is associated with the file, similar to the Invoke-Item cmdlet.
Start-Transcript - The Start-Transcript cmdlet creates a record of all or part of a PowerShell session to a text file. The transcript includes all command that the user types and all output that appears on the console.
Write-Output - The Write-Output cmdlet sends the specified object down the pipeline to the next command. If the command is the last command in the pipeline, the object is displayed in the console. Write-Output sends objects down the primary pipeline, also known as the "output stream" or the "success pipeline." To send error objects down the error pipeline, use Write-Error.
Write-Host - The Write-Host cmdlet customizes output. You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter. The Separator parameter lets you specify a string to use to separate displayed objects. The particular result depends on the program that is hosting PowerShell.
Out-File - The Out-File cmdlet sends output to a file. When you need to specify parameters for the output use Out-File rather than the redirection operator (>).
PowerShell Example
Example PowerShell Script
# Starting the Transcript
Start-Transcript -Path "C:\SovLabs\Notepad++InstallLog.txt"
# Starting Install of Notepad++ 7.8.5
Start-Process -FilePath "C:\SovLabs\npp.7.8.5.Installer.x64.exe" -ArgumentList "/S" -Verb runas -Wait
# Stopping the Transcript
Stop-Transcript
Troubleshooting
Error: File C:\Windows\Temp\scriptname.ps1 cannot be loaded. The file C:\Windows\Temp\scriptname.ps1 is not digitally signed. You cannot run this script on the current system.
Solutions:
Check your execution policy settings inside of PowerShell
If you're the script on a specific node, check to see if there are open PowerShell Processes (Task Manager).
If there are, right click on the task and select "End task".
Error: File was not found Please see the server log to find more detail regarding exact cause of the failure.
Solutions:
Look at the Script Definition and verify that the directory you're using exists on the server
Log into the server and verify the script is getting copied to the server
If not, validate permissions are set correctly
Error: Unable to access file Please see the server log to find more detail regarding exact cause of the failure.
Log into the server and verify the script is getting copied to the server
If not, validate permissions are set correctly
Check to make sure PowerShell is opening in Admin mode
Error: Client received SOAP Fault from server: The attempted operation cannot be performed in the current state (Powered off). Please see the server log to find more detail regarding exact cause of the failure.
Error: com.vmware.vim25.InvalidStateFaultMsg: The operation is not allowed in the current state.
If you're using a Jump Server to execute the scripts, please try rebooting the server
If an error occurs when trying to reboot the server through vCenter, you may need to do a hard shut down of the server
Advanced Troubleshooting
Re-running LCT Token (vRO)
During testing, if a script fails and the VM has NOT been deleted or you're running it against a specific host, you can re-run your LCT token in vRO. This makes testing script changes faster since you do not have to spin up a new VM every time you make a script change.
This will work if you've made changes to the script inside of vRA and want to test your changes.
This will NOT take in any updated properties or anything like that
Process from vRO:
Log into vRO and click on the Workflows Tab
Expand SovLabs → Lifecycle Component → Lifecycle Components Toolkit → Your LCT Workflow
- Right-click on your token and select Run again...
Once the token completes, verify your script/updates worked successfully
Additional information
Plug-in/License
Get SovLabs Plug-in Download Link
How to install a vRA Plug-in
Licensing Infrastructure
Jump Server Configuration
Microsoft AD - Endpoint configuration (Jump Host / WinRM)
Jump Server / VMWare Tools - Account Setup
Lifecycle Toolkit
Lifecycle Toolkit - Examples
Lifecycle Toolkit - Modules and Scripts
Lifecycle Toolkit - Using Lifecycle Toolkit to run multiple scripts dynamically
0 Comments