PowerShell On-Prem plugin
This plugin is one of two available for PowerShell. Make sure to choose the correct version depending on your requirements:
Currently only PowerShell v7 is supported for this plugin.
- PowerShell plugin: Visualize data from PowerShell scripts (cloud only).
- PowerShell On-Prem plugin: Run user-created PowerShell scripts on Relay Agents.
Run user-created PowerShell scripts on Relay Agents.
An on-prem data source connects a service running in your internal network to SquaredUp. They require an agent installed on a machine that has access to your internal network.
To add a data source click on the + next to Data Sources on the left-hand menu in SquaredUp. Search for the data source and click on it to open the Configure data source page.
Before you start
Create the PowerShell scripts
Your PowerShell scripts can serve two different functions:
Import script
In case you need to import new objects into SquaredUp, you need an import script. This script contains the definitions for objects and their links in the Knowledge Graph. There can only be one import script per PowerShell On-Prem data source.
You can add more PowerShell On-Prem data sources to SquaredUp if you want to use different import scripts, and they can all use the same folder.
Data Stream script
All other scripts are Data Stream scripts. Those scripts contain the different Data Streams you want to use when you are creating tiles for a dashboard.
Import scripts return objects to SquaredUp using the following format:
Import scripts write objects to SquaredUp in the following format:
@{
vertices = @()
edges = @()
}
Example import script
Information about parameters in the script:
Vertex (vertices create objects in SquaredUp)
Edges (edges create links between objects in SquaredUp):
get-objects.ps1:
@{
vertices = @(Get-CimInstance -Class Win32_LogicalDisk |
? { $_.DriveType -eq 3 } |
%{
[PSCustomObject]@{
name = ('{0} {1}' -f $_.SystemName,$_.Name)
sourceId = ('\\{0}\root\cimv2:Win32_LogicalDisk.DeviceID="{1}" ({2})' -f $_.SystemName,$_.Name,$_.VolumeSerialNumber)
type="storage"
sourceType="volume"
FileSystem = $_.FileSystem
Compressed = $_.Compressed
Size = $_.Size
}
})
edges = @()
}
Data Stream scripts return objects to SquaredUp using the following format:
Data Stream scripts return data as a simple array of objects:
@()
Example Data Stream script
Data stream scripts are selected when Using the PowerShell On-Prem data streams .
They can also be used when Writing a custom data stream (advanced users) that calls your Data Stream script. This is done from Settings > Advanced > Data Streams.
The format of the result objects of your script needs to match the columns you've defined in the custom Data Stream.
get-diskFreeSpace.ps1:
Param(
[Parameter(Mandatory=$true)]
$scope
)
$targetObjectsBySourceId = @{}
foreach ($targetObject in $scope) {
$targetObjectsBySourceId[$targetObject.sourceId[0]] = $targetObject
}
$results = (Get-CimInstance -Class Win32_LogicalDisk |
? { $_.DriveType -eq 3 } |
%{
$sourceId = '\\{0}\root\cimv2:Win32_LogicalDisk.DeviceID="{1}" ({2})' -f
$_.SystemName,$_.Name,$_.VolumeSerialNumber
if ($targetObjectsBySourceId.ContainsKey($sourceId)) {
[PSCustomObject]@{
name = ('{0} {1}' -f $_.SystemName,$_.Name)
Size = $_.Size
FreeSpace = $_.FreeSpace
}
}
})
return $results
Scripts can optionally define the timeframe parameter, and will receive the tile timeframe as an object with various time representations as properties as follows:
start: "2024-02-19T21:05:00.000Z"
unixStart: 1708376700
end: "2024-02-19T22:05:00.000Z"
unixEnd: 1708380300
enum: "last1hour"
interval: "PT1H"
Configuring and deploying an agent
If you have already created an agent in SquaredUp that you can use for this data source, you can skip this step and choose the agent group you want to use while Configuring the data source.
See one of the following, depending on your platform type:
Configuring the data source
Display Name:
Enter a name for your data source. This helps you to identify this data source in the list of your data sources.Agent Group:
Select the Agent Group that contains the agent(s) you want to use.- Scripts Directory:
Enter the path to the directory where you store the PowerShell scripts on the machine you deployed the agent on.The path must be written as an absolute path, for example
C:\Scripts\SquaredUpCloud
or, if you are using a network share,\\fs01\Scripts\SquaredUpCloud
- Import Script:
Optional. If you want to use a script for importing objects into SquaredUp, you can specify that script here by entering its full file name, for exampleget-objects.ps
The import script must be stored in the same directory you defined above.
- Only allow signed scripts (Windows only):
If you select this checkbox, no unsigned PowerShell scripts will be executed. This applies to all scripts run by the data source, not just the import script. Restrict access to this data source:
You can enable this option if you only want certain users or groups to have access to the data source, or the permission to link it to new workspaces. See Access control for more information.The term data source here really means data source instance. For example, a user may configure two instances of the AWS data source, one for their development environment and one for production. In that case, each data source instance has its own access control settings.
By default, Restrict access to this data source is set to off. The data source can be viewed, edited and administered by anyone. If you would like to control who has access to this data source, switch Restrict access to this data source to on.
Use the Restrict access to this data source dropdown to control who has access to the workspace:
- By default, the user setting the permissions for the data source will be given Full Control and the Everyone group will be given Link to workspace permissions.
- Tailor access to the data source, as required, by selecting individual users or user groups from the dropdown and giving them Link to workspace or Full Control permissions.
- If the user is not available from the dropdown, you are able to invite them to the data source by typing in their email address and then clicking Add. The new user will then receive an email inviting them to create an account on SquaredUp. Once the account has been created, they will gain access to the organization.
- At least one user or group must be given Full Control.
- Admin users can edit the configuration, modify the Access Control List (ACL) and delete the data source, regardless of the ACL chosen.
Access Level:
See Access control for more information.
- Click Add. If you defined an import script, it will run shortly and the objects will subsequently appear in the Map in the new workspace.
Testing and troubleshooting
If you encounter an error, refer to the guidance provided below or contact [email protected] with as much detail as possible for assistance.
Why can’t I see my scripts listed in parameters when configuring a tile?
There is no validation on the script path you enter when setting up the Powershell On-Prem Data Source, ensure the provided path is valid and that any scripts are saved in *.ps1
format.
Why isn’t my script returning expected data?
We’d always recommend ensuring that any scripts will successfully run outside of SquaredUp in the first case, and that data is formatted and returned correctly. If everything looks okay, you may wish to review how the columns are being used in the shaping and columns tabs in the tile configuration.
Next steps
Data streams
The following data streams are installed with this plugin.
Data streams standardize data from all the different shapes and formats your tools use into a straightforward tabular format.
While creating a tile you can tweak data streams by grouping or aggregating specific columns.
Depending on the kind of data, SquaredUp will automatically suggest how to visualize the result, for example as a table or line graph.
Data streams can be either global or scoped:
- Global data streams are unscoped and return information of a general nature (e.g. "Get the current number of unused hosts").
- A scoped data stream gets information relevant to the specific set objects supplied in the tile scope (e.g. "Get the current session count for these hosts").
See Data Streams for more information.
This global data stream allows you to enter and run custom PoweShell scripts.
- Select the run script on-prem data stream. Click Next to go to the Parameters tab.
- Script Path:
Select a script to use. This dropdown displays the scripts you have configured in your scripts folder. - Script Arguments:
Optionally, enter any arguments required by the selected script. These are custom arguments set by the script author in the script itself.Arguments are expressed as a JSON object, where the property name is the name of the parameter, and the value is what should be passed to the script. For example:If the script is not expecting these parameters, including them will cause the stream to fail.
{ "TopN": 10, "filter": ["**/Bin", "*.zip"] }
This scoped data stream allows you to enter and run custom PoweShell scripts.
- Select the run script on-prem data stream. Click Next to go to the Objects tab.
- Select the objects that you want to query. Click Next to go to the Parameters tab.
- Script Path:
Select a script to use. This dropdown displays the scripts you have configured in your scripts folder. - Script Arguments:
Optionally, enter any arguments required by the selected script. These are custom arguments set by the script author in the script itself.Arguments are expressed as a JSON object, where the property name is the name of the parameter, and the value is what should be passed to the script. For example:If the script is not expecting these parameters, including them will cause the stream to fail.
{ "TopN": 10, "filter": ["**/Bin", "*.zip"] }
Writing a custom data stream (advanced users)
Optionally, you can choose to create your own custom data streams.
Data streams standardize data from all the different shapes and formats your tools use into a straightforward tabular format.
While creating a tile you can tweak data streams by grouping or aggregating specific columns.
Depending on the kind of data, SquaredUp will automatically suggest how to visualize the result, for example as a table or line graph.
Data streams can be either global or scoped:
- Global data streams are unscoped and return information of a general nature (e.g. "Get the current number of unused hosts").
- A scoped data stream gets information relevant to the specific set objects supplied in the tile scope (e.g. "Get the current session count for these hosts").
See Data Streams for more information.
- Go to Settings > Advanced > Data Streams.
- Add a new Data Stream with the following settings:
- Enter the JSON for the Data Stream in the code box.
Information about parameters in the script:
{ "name": "diskSpace", "dataSourceConfig": { "scriptPath": "get-diskFreeSpace.ps1" }, "matches": { "sourceType.0": { "type": "equals", "value": "volume" } }, "rowPath": [ "results" ], "metadata": [] }