Question
Invoke-command: variable $input
- buart Ludovic
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 13 ans 8 mois #12408
par buart Ludovic
Invoke-command: variable $input a été créé par buart Ludovic
Bonjour à tous,
J'interroge l'A.D. à distance via la cmdlet invoke-command et j'aimerais ressortir la \"Description\" d'un objet ciblé par la propriété \"Name\".
Quand je fais cette commande:
invoke-command -computername $DC -credential $cred {$filtre = \"(objectCategory=Computer)\";$domaine = New-Object System.DirectoryServices.DirectoryEntry;$chercheur = New-Object system.DirectoryServices.DirectorySearcher;$chercheur.SearchRoot = $domaine;$chercheur.PageSize = 1000; $chercheur.Filter = $filtre;$colResults = $chercheur.FindAll();foreach ($objResult in $colResults) {$objItem = $objResult.Properties; if($objitem.name -eq \"nomobject\"){$objItem.Description}}}
j'ai bien la description.
J'aimerais une variable à la place du nom de l'objet et donc ma commande devient:
invoke-command -computername $DC -credential $cred -inputobject $srv {$filtre = \"(objectCategory=Computer)\";$domaine = New-Object system.DirectoryServices.DirectoryEntry;$chercheur = New-Object System.DirectoryServices.DirectorySearcher;$chercheur.SearchRoot = $domaine;$chercheur.PageSize = 1000; $chercheur.Filter = $filtre;$colResults = $chercheur.FindAll();foreach ($objResult in $colResults) {$objItem = $objResult.Properties;if($objitem.name -eq $input){$objItem.Description}}}
Mais le résultat est nul et j'ai remarqué que je perd ma variable input avant d'exécuter \"if($objitem.name -eq $input){$objItem.Description}\".
Quelqu'un peut m'aider?<br><br>Message édité par: Loeizbzh, à: 19/07/12 14:45
J'interroge l'A.D. à distance via la cmdlet invoke-command et j'aimerais ressortir la \"Description\" d'un objet ciblé par la propriété \"Name\".
Quand je fais cette commande:
invoke-command -computername $DC -credential $cred {$filtre = \"(objectCategory=Computer)\";$domaine = New-Object System.DirectoryServices.DirectoryEntry;$chercheur = New-Object system.DirectoryServices.DirectorySearcher;$chercheur.SearchRoot = $domaine;$chercheur.PageSize = 1000; $chercheur.Filter = $filtre;$colResults = $chercheur.FindAll();foreach ($objResult in $colResults) {$objItem = $objResult.Properties; if($objitem.name -eq \"nomobject\"){$objItem.Description}}}
j'ai bien la description.
J'aimerais une variable à la place du nom de l'objet et donc ma commande devient:
invoke-command -computername $DC -credential $cred -inputobject $srv {$filtre = \"(objectCategory=Computer)\";$domaine = New-Object system.DirectoryServices.DirectoryEntry;$chercheur = New-Object System.DirectoryServices.DirectorySearcher;$chercheur.SearchRoot = $domaine;$chercheur.PageSize = 1000; $chercheur.Filter = $filtre;$colResults = $chercheur.FindAll();foreach ($objResult in $colResults) {$objItem = $objResult.Properties;if($objitem.name -eq $input){$objItem.Description}}}
Mais le résultat est nul et j'ai remarqué que je perd ma variable input avant d'exécuter \"if($objitem.name -eq $input){$objItem.Description}\".
Quelqu'un peut m'aider?<br><br>Message édité par: Loeizbzh, à: 19/07/12 14:45
Connexion ou Créer un compte pour participer à la conversation.
- buart Ludovic
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 13 ans 8 mois #12409
par buart Ludovic
Réponse de buart Ludovic sur le sujet Re:Invoke-command: variable $input
C'est bon j'ai trouvé, j'utilise param() et -argumentlist.
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.032 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Invoke-command: variable $input