“Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))” al crear un grupo

Esto me sucedió al ejecutar un script para crear un grupo Active Directory:
Ejecutaba el siguiente script:

#This code demonstrates how to create a new group object on Active Directory and add user ID’s
#to the group without any plug-ins.
#To run this script within your environment you should only need to copy and paste this script into
#either Windows Powershell ISE or PowerGUI Script Editor,(http://powergui.org) with the following
#changes to the script which I have numbered below.
# 1.) Change the line, ($userlist = “UserID1″,”UserID2″,”UserID3”), so that you have real User ID’s.
# 2.) Change the line, ($GroupName = “TesterGroup1234”), so that you have the real group name you
# want to create.
# 3.) You may also need to install Microsoft Update “http://support.microsoft.com/kb/968930”.
#
# You may need to change the PageSize value depending on how big your Active Directory structure is.
#
#You can also search in a specific Active Directory OU’s By changing the sections of
#code that have “System.DirectoryServices.DirectoryEntry” listed within them.
#From: “$objDomain = New-Object System.DirectoryServices.DirectoryEntry”
#To: “$objDomain = New-Object System.DirectoryServices.DirectoryEntry(“LDAP://OU=ASDF,DC=asdf,DC=asdf”)”

Function Get-UserDN
{
# The array variable “$args[0]” is how to capture variable sent to the function, (i.e. “Get-UserDN UserID”).
# If you increment the number within the variable $args[0] to $args[1] or $args[2] you are able to capture
# additional variables sent to the function, (i.e. “Get-UserDN UserID1 UserID2 UserID3”
$strUserName = $args[0]
$objDomain2 = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$strFilter = “(&(objectCategory=User)(samAccountName=” + $strUserName + “))”
$objSearcher.SearchRoot = $objDomain2
$objSearcher.PageSize = 5000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = “Subtree”
$colResults = $objSearcher.FindAll()
foreach ($objResult in $colResults)
{
$objResult.Path
}
}

#Beginning of PowerShell code:
#First change the variable $userlist to real User ID’s within your domain.
$userlist = “UserID1″,”UserID2″,”UserID3”

$ADS_GROUP_TYPE_GLOBAL_GROUP = 0x00000002
$ADS_GROUP_TYPE_LOCAL_GROUP = 0x00000004
$ADS_GROUP_TYPE_UNIVERSAL_GROUP = 0x00000008
$ADS_PROPERTY_APPEND = 3

$ADS_GROUP_TYPE_SECURITY_ENABLED = “&H80000000”

$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$GroupName = “TesterGroup1234”
$objGroup = $objDomain.Create(“group”, “CN=” + $GroupName)

# in this example we are creating a Local group to change this to a global group or universal group
# replace the the text “$ADS_GROUP_TYPE_GLOBAL_GROUP” with either “$ADS_GROUP_TYPE_GLOBAL_GROUP”
# or “$ADS_GROUP_TYPE_UNIVERSAL_GROUP” on the line below.
$objGroup.Put(“groupType”, $ADS_GROUP_TYPE_LOCAL_GROUP -bor $ADS_GROUP_TYPE_SECURITY_ENABLED)

#Note: You can change ghe group type to a Distribution group instead of being a Security group by
#removing “-bor $ADS_GROUP_TYPE_SECURITY_ENABLED”.
#Example: $objGroup.Put(“groupType”, $ADS_GROUP_TYPE_LOCAL_GROUP)

$objGroup.Put(“sAMAccountName”, $GroupName )
$objGroup.Put(“Description”,”Some Descriptive text”)
$objGroup.Put(“Info”,”Additional information”)
$objGroup.SetInfo()
#Note, you have to create the group with SetInfo() before you can add users to the group.
foreach ($i in $userlist)
{
$strUserDN = Get-UserDN $i
$objGroup.add($strUserDN)
$objGroup.SetInfo()
}

que se encuentra en el siguiente link:

Link

Sucede que se mostraban 3 errores con el mismo texto:

Exception calling “add” with “1” argument(s): “Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))”
At line:71 char:14
+ $objGroup.add <<<< ($strUserDN)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

Descubrí que se debía a que al reemplazar los nombres de los usuarios ponía nombres de usuarios que no había creado, es que el script no crea los usuarios sino que ya deben de estar creados, así, luego de crear los 3 usuarios los reemplazé y el script no dió ningún error.

He probado esto con PowerShell V2 sobre Windows Server 2003 SP2.
Aver si le sirve a alguien.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s


A %d blogueros les gusta esto: