Importing Roles with MilestonePSTools

Hi, I have installed MilestonePSTools to my workstations and created a .json file to import a new role with overall security set. I had received a command to add for importing the file to the management server as seen below: -

Connect-ManagementServer -AcceptEula -Server (ServerName) -Credential (Get-Credential)

[add](javascript:void(0); “add”) overall security settings as defined in the respective json files

[if](javascript:void(0); “if”) role exist: Existing role permissions will be overwritten

[if](javascript:void(0); “if”) role does not exist: Role will be created and settings applied

Import-Role -Path .\overallsecurity_generalstaff.json -Confirm:$false

Disconnect-ManagementServer

It seems Import-Role function is not recognised as I receive the below: -

The term ‘Import-Role’ is not recognized as the name of a cmdlet, function, script file, or operable program.

I have noticed from some MilstonePSTools videos that some functions on the video do not exist on mine. Is this a version issue as I have the most recent version, or do I need to install additional features to the module? Or is there a completely different function to use that I may be over looking?

Hi @James Tyler​,

About two years ago I pushed a MilestonePSTools.Security module to PowerShell Gallery which includes the following functions:

  • Export-Role
  • Import-Role
  • Set-RoleMembership
  • Get-ViewGroupPermission
  • Set-ViewGroupPermission

If you install this module in addition to MilestonePSTools, you should have the Import-Role function available to you. However it’s been a while since I’ve used those functions so your mileage may vary. Like any exploration/testing of an automation tool, please try it out in a test environment or at least perform a configuration backup in Management Client.

Install-Module -Name MilestonePSTools.Security

Back in 2021 my thinking was that the core MilestonePSTools module should be as “un-opinionated” as possible. That it should more or less provide the basic “CRUD” (create, read, update, delete) functions for all the resource types (cameras, users, events, etc). Then some opinionated functions could be provided in separate modules for bulk import/export via a specific file type, or for more specialized reporting for example.

Ultimately I’m leaning toward wanting to provide those simple import/export functions in the core module and avoid having modules on the side for now. For even more specialized functions/scripts/examples, we would host them at MilestonePSTools.com and/or in the PowerShellSamples GitHub repo. Hopefully that older Import-Role function works for you as-is since you’ve already invested some time into preparing your JSON. Going forward I expect to add Export-VmsRole and Import-VmsRole functions to accompany the recently added *VmsRole* functions available in the latest release of MilestonePSTools:

Hi @Josh Hendricks (Milestone Systems)​

Thanks you for this. The functions work well.

Only thing is I cannot import new roles (Power User for this example) as I receive the bellow warning: -

WARNING: Skipping Power User because the role does not exist and was unable to be created

I am running the below script in PowerShell ISE: -

Connect-ManagementServer -AcceptEula -Server (Management Server) -Credential (Get-Credential)

[add](javascript:void(0); “add”) overall security settings as defined in the respective json files

[if](javascript:void(0); “if”) role exist: Existing role permissions will be overwritten

[if](javascript:void(0); “if”) role does not exist: Role will be created and settings applied

Import-Role -Path .\Import.json -Confirm:$false

Disconnect-ManagementServer

Is there any additional information to add on the ‘Import-Role’ line?

This script works in overwriting a role that already exists, just not adding new roles.