Peter Hinchley

Learning in Public

✪ Add a User to HPE Content Manager using PowerShell

The following PowerShell code will add a new user to HPE Content Manager. There a few things you will need to do before using the code. Firstly, you will need to change the dataset and workgroupServer variables as appropriate for your environment. Secondly, you will need to copy the following DLLs from the Content Manager server to the C:\TRIM folder of the computer from which you will execute the code. The files can be found under the C:\Program Files\Hewlett Packard Enterprise\Content Manager folder.

Note: The code will need to execute under the context of an account with administrator access to Content Manager.

Add-Type -Path "C:\TRIM\HP.HPTRIM.SDK.dll"

$dataset = 'XX'
$workgroupServer = 'TRIM'

function add-trimuser($username, $givenName, $sn, $email, $expiry) {
  $database = New-Object HP.HPTRIM.SDK.Database

  $database.Id = $script:dataset
  $database.WorkgroupServerName = $script:workgroupServer
  $database.Connect()

  # search for the user by login id.
  $people = New-Object HP.HPTRIM.SDK.TrimMainObjectSearch($database, [HP.HPTRIM.SDK.BaseObjectTypes]::Location)
  $people.SetSearchString("LogIn:$username")

  # exit if the user already exists.
  if ($people.count -ne 0) { write-warning 'The user already has a HPE Content Manager account.'; return $false }

  $person = New-Object HP.HPTRIM.SDK.Location($database, [HP.HPTRIM.SDK.LocationType]::Person)

  $person.givenNames = $givenName
  $person.surname = $sn
  $person.initials = $givenName.substring(0, 1) + $sn.substring(0, 1)

  $person.logsInAs = $username

  $person.emailAddress = $email
  $person.userType = 'RecordsWorker'

  # work out expiration dates.
  $from = '1/01/0001'
  if ($expiry -eq $null) { $to = $expiry = '' }
  else { $to = $expiry }

  $person.loginexpires = $expiry
  $person.setActiveDateRange($from, $to)

  # add relevant associations for the user.
  # $person.addrelationship('Something', 'MemberOf', $true)

  # accept logins.
  $person.canlogin = $true

  # set default security level.
  $person.securitystring = 'UNCLASSIFIED, FOR OFFICIAL USE ONLY'

  # set internal status.
  $person.iswithin = $true

  $person.save()

  $database.dispose()
}

# example usage.
$user = get-aduser jbloggs -properties mail, accountExpirationDate
add-trimuser $user.sAMAccountName $user.givenName $user.surname $user.mail $user.accountExpirationDate