The Particular.
module can be installed from the PowerShell Gallery, and is used to add, remove, update and delete instances of ServiceControl.
Prerequisites
The ServiceControl PowerShell module requires PowerShell Core 7.2 or later, or Windows PowerShell 5.1.
Installing and using the PowerShell module
In order to use the PowerShell module, the PowerShell execution policy needs to be set to RemoteSigned
. Refer to the PowerShell documentation on how to change the execution policy.
The module can be installed from the PowerShell Gallery with the following command:
Install-Module -Name Particular.ServiceControl.Management
Once the module is installed, it can be used by importing the module into the PowerShell session with the following command:
Import-Module Particular.ServiceControl.Management
To obtain the version of the installed management module the following command can be used:
Get-Module Particular.ServiceControl.Management | Select-Object -ExpandProperty Version
The majority of the cmdlets will only work if the PowerShell session is running with administrator privileges.
The ServiceControl installer currently includes a legacy version of the PowerShell module called ServiceControlMgmt
that is only supported on Windows PowerShell 5.1. It does not work with newer versions of PowerShell. The ServiceControl installer creates a shortcut in the Windows start menu to launch an administrative PowerShell Session with this legacy module automatically loaded. The legacy module is not signed, so the PowerShell execution policy needs to be set to Unrestricted
to use it.
Method not found: 'System.
This indicates that the PowerShell module is being executed using a newer version of PowerShell than it supports. To resolve this issue, make sure to use the PowerShell module hosted on the PowerShell Gallery.
Audit instance Cmdlets and Aliases
The following cmdlets and aliases are provided by the ServiceControl Management PowerShell module for managing Audit instances.
Alias | Cmdlet |
---|---|
audit-add | New-ServiceControlAuditInstance |
audit-delete | Remove-ServiceControlAuditInstance |
audit-instances | Get-ServiceControlAuditInstances |
audit-upgrade | Invoke-ServiceControlAuditInstanceUpgrade |
The following cmdlets are available for the management of ServiceControl remotes.
Alias | Cmdlet |
---|---|
sc-addremote | Add-ServiceControlRemote |
sc-deleteremote | Remove-ServiceControlRemote |
sc-remotes | Get-ServiceControlRemotes |
The following general cmdlets and aliases are provided by the ServiceControl Management PowerShell module.
Alias | Cmdlet |
---|---|
sc-addlicense | Import-ServiceControlLicense |
sc-findlicense | Get-ServiceControlLicense |
sc-transportsinfo | Get-ServiceControlTransportTypes |
sc-help | Get-ServiceControlMgmtCommands |
urlacl-add | Add-UrlAcl |
urlacl-delete | Remove-UrlAcl |
urlacl-list | Get-UrlAcls |
port-check | Test-IfPortIsAvailable |
user-sid | Get-SecurityIdentifier |
Help
All of the cmdlets have local help which can be accessed via the standard PowerShell help command
Get-Help Get-ServiceControlManagementCommands
Deploying an Audit instance
Using PowerShell, deploy the ServiceControl Error instance first, then deploy the ServiceControl Audit instance using the New-ServiceControlAuditInstance
cmdlet:
$auditInstance = New-ServiceControlAuditInstance `
-Name Test.ServiceControl.Audit `
-InstallPath C:\ServiceControl.Audit\Bin `
-DBPath C:\ServiceControl.Audit\DB `
-LogPath C:\ServiceControl.Audit\Logs `
-Port 44444 `
-DatabaseMaintenancePort 44445 `
-Transport MSMQ `
-AuditQueue audit1 `
-AuditRetentionPeriod 10:00:00:00 `
-ForwardAuditMessages:$false `
-ServiceControlQueueAddress Test.ServiceControl
Use the Get-Help
cmdlet for a full list of parameters available.
Use the Get-ServiceControlTransportTypes
cmdlet to determine the correct -Transport
value to use. See the ServiceControl transport guide for transport configuration options via the connection string.
The address of a ServiceControl Error instance must be provided to send notifications to.
Once a ServiceControl Audit instance is created, it must be added to the ServiceControl Error instance as a remote to be included in results returned to ServiceInsight. Use the Add-ServiceControlRemote
cmdlet to add a remote to the Error instance:
Add-ServiceControlRemote `
-Name $serviceControlInstance.Name `
-RemoteInstanceAddress $auditInstance.Url
Listing deployed instances
Use the Get-ServiceControlAuditInstances
cmdlet to find a list of all of the ServiceControl Audit instances and their version numbers:
Get-ServiceControlAuditInstances | Select Name, Version
Removing an instance
Before removing a ServiceControl Audit instance, it should be removed from the ServiceControl Error instance's registered remotes using the Remove-ServiceControlRemote
cmdlet:
Remove-ServiceControlRemote `
-Name Test.ServiceControl `
-RemoteInstanceAddress http://localhost:44444/api
Use the Remove-ServiceControlAuditInstance
cmdlet to remove the instance and delete the database and logs:
Remove-AuditInstance `
-Name Test.ServiceControl.Audit
-RemoveDB -RemoveLogs
Upgrading a instance
The ServiceControl PowerShell module must be updated to deploy a newer version of a ServiceControl instance, as the binaries are embedded in the module version that is installed.
To update the PowerShell module use the following command:
Update-Module -Name Particular.ServiceControl.Management
Once the PowerShell module is updated, use the Invoke-ServiceControlAuditInstanceUpgrade
cmdlet to upgrade the Audit instance to the installed version:
Invoke-ServiceControlAuditInstanceUpgrade -Name InstanceToUpgrade
If the instance is running when the upgrade starts, it will be shut down during the upgrade and restarted once the upgrade is complete.
Before the upgrade begins the configuration file of the existing version is examined to determine if all of the required settings are present. If a configuration setting is missing then the cmdlet will throw an error indicating the required additional parameter for the cmdlet.
Additional parameters may be required when upgrading instances. See the upgrade guide for the specific version for more details.
Licensing
Copies the license file to the machine-wide license location so it is available to all instances of ServiceControl installed on the machine.
Import-ServiceControlLicense License.xml
Troubleshooting via PowerShell
The ServiceControl Management PowerShell module offers some cmdlets to assist with troubleshooting the installation of ServiceControl instances.
Check if a port is already in use
Before adding an instance of ServiceControl test if the port to use is currently in use.
Test-IfPortIsAvailable -Port 33333
This example shows the available ports out of a range of ports
33330..33339 | Test-IfPortIsAvailable | ? Available
If the port is already in use, then choose a different port.
Checking and manipulating UrlAcls
The Window HTTPServer API is used by underlying components in ServiceControl. This API uses a permissions system to limit what accounts can add a HTTP listener to a specific URI. The standard mechanism for viewing and manipulating these ports is with the netsh.exe command line tool.
For example netsh.
will list all of the available UrlAcls. This output is detailed but not easy to query. The ServiceControl Management PowerShell provides simplified PowerShell equivalents for listing, adding, and removing UrlAcls and makes the output easier to query.
For example the following command lists all of the UrlAcls assigned to any URI for port 33333.
Get-UrlAcls | ? Port -eq 33333
In this example any UrlAcl on port 33335 is removed
Get-UrlAcls | ? Port -eq 33335 | Remove-UrlAcl
The following example shows how to add a UrlAcl for a ServiceControl service that should only respond to a specific DNS name. This would require an update of the ServiceControl configuration file as well. Refer to setting a custom host name and port number
Add-UrlAcl -Url http://servicecontrol.mycompany.com:33333/api/ -Users Users