GetComputerRole

Returns the computer role with a specified name.

Syntax

IComputerRole GetComputerRole (string name)

Parameter

Specify the following parameter when using this method:

Parameter Description
name The name of the computer role.

Return value

The computer role with the specified name, or null if no match is found.

Exceptions

GetComputerRole throws an ApplicationException if it can’t find authorization data for the zone or if it failed to get the computer role (see the message returned by the exception for the reason).

Example

The following code sample illustrates using the GetComputerRole method in a script:

...
IHierarchicalZone objZone =
cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN) as IHierarchicalZone;

if (objZone == null)
{
Console.WriteLine("Zone " + strZone + " does not exist.");
}
else
{
IComputerRole compRole = objZone.GetComputerRole(strName);
if (compRole != null)
{
Console.WriteLine("Computer role " + strName + " already exist.");
}
else
{
compRole = objZone.AddComputerRole(strName);
compRole.Group = strGroup;
compRole.Validate();
compRole.Commit();
Console.WriteLine("Computer role " + strName + " is created successfully.");
}
}
...