Have a Question?

If you have any question you can ask below or enter what you are looking for!

Executing custom powershell scripts

Summary

Starting with CloudPanel 3.2.302.0 you can now execute your own powershell scripts after certain actions such as adding a new company, adding a new user or even deleting a user. This is done by reading a certain powershell script located in the C:\Program Files (x86)\Know More IT\CloudPanel\Content\powershell directory.

This feature also allows you to pass certain variables from CloudPanel to the powershell script. Each action may contain different variables that are valid only for that action.

How To

CloudPanel currently has five actions that are available to execute a custom powershell script after:

  • Adding a new company (AddCompany.ps1)
  • Updating a company (UpdateCompany.ps1)
  • Deleting a company (DeleteCompany.ps1)
  • Adding a new user (AddUser.ps1)
  • Deleting a user (DeleteUser.ps1)

The following variables are available but some may not be available for all actions:

  • CompanyCode
  • CompanyName
  • CompanyDistinguishedName
  • Reference
  • DomainName
  • UserPrincipalName
  • SamAccountName
  • UserDistinguishedName

Simply add the powershell scripts you want to execute. If the file doesn’t exist then it won’t try to execute a powershell script after the action.

Troubleshooting

CloudPanel will read your powershell script and inject the variables listed below. The variables are case sensitive and do not have to be used if you don’t want to.

If a powershell script fails, then CloudPanel will revert the changes it made but NOT the changes your powershell script made. For example if you create a new company and the script fails, then CloudPanel will clean up and remove the company it just created but the actions by your custom powershell script will remain.

AddCompany.ps1

Below is a list of variables supported by the AddCompany powershell script.

Variable Description
$CompanyCode
The unique code for the new company you just created
$CompanyName
The company name of the company you just created
$CompanyDistinguishedName
The distinguished name of the company in Active Directory
$DomainName
The domain name used when creating the company
$Reference
The value from the reference field

UpdateCompany.ps1

Below is a list of variables supported by the UpdateCompany powershell script.

Variable Description
$CompanyCode
The unique code for the new company you just created
$CompanyName
The company name of the company you just created
$CompanyDistinguishedName
The distinguished name of the company in Active Directory
$Reference
The value from the reference field

DeleteCompany.ps1

Below is a list of variables supported by the DeleteCompany powershell script.

Variable Description
$CompanyCode
The unique code for the new company you just created
$CompanyName
The company name of the company you just created
$CompanyDistinguishedName
The distinguished name of the company in Active Directory
$Reference
The value from the reference field

AddUser.ps1

Below is a list of variables supported by the AddUser powershell script.

Variable Description
$CompanyCode
The unique code for the new company you just created
$CompanyName
The company name of the company you just created
$CompanyDistinguishedName
The distinguished name of the company in Active Directory
$Reference
The value from the reference field
$UserPrincipalName
The new user's UserPrincipalName
$SamAccountName
The new user's sAMAccountName
$UserDistinguishedName
The new user's distinguished name

DeleteUser.ps1

Below is a list of variables supported by the DeleteUser powershell script.

Variable Description
$CompanyCode
The unique code for the new company you just created
$UserPrincipalName
The new user's UserPrincipalName
$SamAccountName
The new user's sAMAccountName
$UserDistinguishedName
The new user's distinguished name