Home > Software engineering >  Remove users from application using LithnetRMA
Remove users from application using LithnetRMA

Time:11-27

Im using LithnetRMA to update MIM application membership. I have multiple users who are linked to an application (ObjectID: 168b8077-052c-489d-b4c0-1700ff817d1f) I would like to remove several users who have left the company. Not sure if im on the right path?

# Load the Lithnet Service PowerShell module
Import-Module LithnetRMA

$userList = @"
ObjectID;
139b8058-052c-459d-b3c0-1600fo417d1a
195b8057-042c-439d-b2c0-1800fp117d1b
169b8047-022c-449d-b0c0-1900fi217d1c
162b8037-012c-489d-b1c0-1000fu417d1d
164b8027-002c-488d-b8c0-1300fy317d1e
163b8017-012c-449d-b7c0-1500fr517d1f
"@

   


#Remove users from the application
foreach($item in $userList) {

#Get the users and application objects
$user = Get-Resource -ID $item.ObjectID
$application = Get-Resource -ID "168b8077-052c-489d-b4c0-1700ff817d1f"

$application.ExplicitMember.Remove($item.ObjectID)
Save-Resource -Resources $application
}

CodePudding user response:

I can't speak to the LithnetRMA part, but it looks like your intent is to define $userList as an array of objects that have an .ObjectId property, but in reality you're simply assigning a single, multiline string.

Therefore, change your assignment as follows:

# Parse the string into objects that have an .ObjectID property.
$userList = ConvertFrom-Csv @"
ObjectID
139b8058-052c-459d-b3c0-1600fo417d1a
195b8057-042c-439d-b2c0-1800fp117d1b
169b8047-022c-449d-b0c0-1900fi217d1c
162b8037-012c-489d-b1c0-1000fu417d1d
164b8027-002c-488d-b8c0-1300fy317d1e
163b8017-012c-449d-b7c0-1500fr517d1f
"@

ConvertFrom-Csv is used to parse the multiline string into the objects of interest, by interpreting the string as single-column CSV data.

Note that the trailing ; was removed from the ObjectID line so that the ; doesn't become part of the property name. (It would be ignored if you used ConvertFrom-Csv -Delimiter ';', however.)

  • Related