Question créer une machine dans l'AD à partier d'un CSV

Plus d'informations
il y a 13 ans 11 mois #11868 par darphboubou
Bonjour,

J'ai un fichier CSV (nomé aasset1.csv) de cette forme

AssetTag,Type
001,Destop
002,Laptop


J'importe ce CSV dans le script suivant


#import du fichier CSV
$dataSource=Import-CSV \"C:\Users\Administrator\Documents\asset1.csv\"

ForEach($dataRecord in $datasource) {
$AssetTag = $dataRecord.AssetTag
$Type = $dataRecord.Type

#determine le nom de la machine à partir du CSV
$ComputerName = $Type.substring(0,1) + $AssetTag
$SAMAccountNAme=$ComputerNAme + \"$\"

#Determine l'OU auquel sera rattaché la machine
$strOUADsPath = \"LDAP://OU=\" +$Type + \"S\" + \",OU=client,DC=contoso,DC=com\"

$objOU=[ADSI]$strOUADsPath
$objOU

Mon soucis est le suivant lorsque j'essai d'obtenir le DN de la machine j'obtiens le message d'erreur suivant

The following exception occurred while retrieving member \"PSComputerName\": \"There is no such object on the server.
\"
+ CategoryInfo : NotSpecified: (:) [format-default], ExtendedTypeSystemException
+ FullyQualifiedErrorId : CatchFromBaseGetMember,Microsoft.PowerShell.Commands.FormatDefaultCommand


Pouvez-vous me dire ou je foire?

Merci

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 11 mois #11869 par Richard Lazaro
Bonjour,

Il me semble que cette erreur survient quand ADSI n'arrive pas à contacter ton LDAP.

Bien Cordialement,
Richard Lazaro.

Think-MS : (Get-Life).Days | %{ Learn-More }

\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 11 mois #11870 par darphboubou
Pourtant je travaille directement sur mon DC sur lequel se trouve mon LDAP

cette ligne de commande

$strOUADsPath = \"LDAP://OU=\" +$Type + \"S\" + \",OU=client,DC=contoso,DC=com\"

me donne
LDAP://OU=DESKTOPS,OU=client,DC=contoso,DC=com

comment lui faire comprendre que je veux ce resultat entouré de guillemets, comme ci-dessous
\"LDAP://OU=DESKTOPS,OU=client,DC=contoso,DC=com\"

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 11 mois #11871 par SiSMik
[code:1]$strOUADsPath = '\"LDAP://OU=' +$Type + 'S' + ',OU=client,DC=contoso,DC=com\"'[/code:1]

Quelquechose du style devrait te permettre de garder les guillemets.

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 13 ans 11 mois #11872 par Richard Lazaro
Ou bien :

[code:1]
$objOU=[ADSI]('LDAP://OU={0}S,OU=client,DC=contoso,DC=com' -f $Type)
[/code:1]

Dans ce cas, j'utilise la technqiue de formatage de chaîne de caractère.

Bien Cordialement,
Richard Lazaro.

Think-MS : (Get-Life).Days | %{ Learn-More }

\\"Problems cannot be solved by the same level of thinking that created them.\\" - Albert Einstein

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.041 secondes
Propulsé par Kunena