locked
Add many Views in User role using powershell RRS feed

  • Question

  • Should be added nearly 300 views in 30 user role. In the SCSM console, it takes a lot of time to do. I know smelt Update-SCSMUserRole, but it seems not supported the function "add view"

    How to do it using PowerShell?
    Friday, May 24, 2013 8:54 AM

Answers

  • You will have to use the native scsm cmdlets. The easiest way is to copy the views from one UserRole to the other(s).

    Here is an example:

    Import-Module "C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets.psd1"
    
    $SourceUserRole = Get-SCSMUserRole -DisplayName "Test Resolvers"
    $TargetUserRole = Get-SCSMUserRole -Displayname "Test2 Resolvers"
    
    $TargetUserRole.View = $SourceUserRole.View
    Update-SCSMUserRole -UserRole $TargetUserRole

    I hope you can figure out the foreach part if you want to update a bunch of user roles.

    However, you could take a another approach for this: Make one generic User Role that has all the right views, tasks etc. Then put all the AD users in that role from the other 30 or so you have. In the other 30 user roles, you check the "Provide only access to the selected views/tasks etc." and mark nothing (or mark just the specific ones for that user role). This way you only have to update 1 user role istead of 30.

    Monday, May 27, 2013 6:52 PM

All replies

  • use the SCSM powershell module.

    Using a combination of get-SCSMUserRole and Update-SCSMUserRole or New-SCSMUserRole for that matter.

    examples can be found here:

    http://technet.microsoft.com/en-us/library/hh316218.aspx

    Example:

    #get a user role
    $Role = Get-SCSMUserRole -Name MyUserRoleName
    $Views = $Role.View
    
    #Create a new user role
    $RoleArguments = @{
      UserRoleType = "ReadOnlyOperator"
      DisplayName = "Some Name"
      Queue = @()
      Group = @()
      Task = @()
      View = $Views
      User = "DOMAIN\MyUser"
      }
    New-SCSMUserRole @RoleArguments
    
    #Code is not validated
    #Update process is similar
    Hope it helps

    Stijn Callebaut

    Friday, May 24, 2013 10:16 AM
  • Thank you, for reply.

    It works when creating a new role, but in my situation, the User roles are created. I need update them.


    Friday, May 24, 2013 10:33 AM
  • You will have to use the native scsm cmdlets. The easiest way is to copy the views from one UserRole to the other(s).

    Here is an example:

    Import-Module "C:\Program Files\Microsoft System Center 2012\Service Manager\Powershell\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets\Microsoft.EnterpriseManagement.ServiceManager.Cmdlets.psd1"
    
    $SourceUserRole = Get-SCSMUserRole -DisplayName "Test Resolvers"
    $TargetUserRole = Get-SCSMUserRole -Displayname "Test2 Resolvers"
    
    $TargetUserRole.View = $SourceUserRole.View
    Update-SCSMUserRole -UserRole $TargetUserRole

    I hope you can figure out the foreach part if you want to update a bunch of user roles.

    However, you could take a another approach for this: Make one generic User Role that has all the right views, tasks etc. Then put all the AD users in that role from the other 30 or so you have. In the other 30 user roles, you check the "Provide only access to the selected views/tasks etc." and mark nothing (or mark just the specific ones for that user role). This way you only have to update 1 user role istead of 30.

    Monday, May 27, 2013 6:52 PM
  • Thank you!

    You helped me very much!

    Monday, June 3, 2013 6:43 AM