AddUnixProfile
Adds a new UNIX profile for an existing Active Directory user account to the specified zone.
Syntax
IUserUnixProfile AddUnixProfile (IZone zone, int uid, string name, string shell, string homeDir, int primaryGroup)
IUserUnixProfile AddUnixProfile (IZone zone, long uid, string name, string shell, string homeDir, long primaryGroup)
Parameters
Specify the following parameters when using this method.
Parameter | Description |
zone |
The destination zone for the new user information. |
uid |
The UID of the user associated with the profile. |
name |
The UNIX login name of the user associated with the profile. |
shell |
The default shell of the user associated with the profile. |
homeDir |
The default home directory of the user associated with the profile. |
primaryGroup |
The GID of the primary group of the user associated with the profile. |
Return value
A new UserUnixProfile object.
Discussion
There are two versions of this method: one designed for COM-based programs that supports a 32-bit signed number for the uid and primaryGroup arguments and one designed for .NET-based programs that allows a 64-bit signed number for the arguments.
Exceptions
AddUnixProfile throws a NotSupportedException if the zone schema is not supported.
Example
The following code sample illustrates using AddUnixProfile in a script:
... // Create a CIMS object to interact with AD ICims cims = new Cims(); // Note the lack of the cims.connect function. // By default, this application will use the connection to the domain controller // and existing credentials from the computer already logged in. // Get the user object IUser objUser = cims.GetUserByPath(strUser); // Get the zone object IZone objZone = cims.GetZoneByPath("cn=" + strZone + "," + strContainerDN); IUserUnixProfile objUserUnixProfile; if (objUser.UnixProfiles.Find(objZone) == null) { //New user for the zone long lngUID = objZone.NextUID; string strShell = objZone.DefaultShell; string strHome = objZone.DefaultHomeDirectory; if (bool.Parse(bPrivate)) { // Create the user as a member of a private group objUserUnixProfile = objUser.AddUnixProfile(objZone, lngUID, strUnixAccount, strShell, strHome, lngUID); } else { // Create the user as a member of the default group IGroupUnixProfile objDefaultGroup = objZone.DefaultGroup; long lngGID = 10000; // use 10000 as default if (objDefaultGroup != null) { lngGID = objDefaultGroup.GroupId; } objUserUnixProfile = objUser.AddUnixProfile(objZone, lngUID, strUnixAccount, strShell, strHome, lngGID); } // Enable the UNIX profile for the end user objUserUnixProfile.UnixEnabled = true; objUserUnixProfile.Commit(); } else { Console.WriteLine(strUser + " is already a member of " + strZone); return; } Console.WriteLine("User " + strUser + " was successfully added to zone " + strZone + "."); ...