Question Invoke-command: variable $input

Plus d'informations
il y a 13 ans 8 mois #12408 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

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

Plus d'informations
il y a 13 ans 8 mois #12409 par buart Ludovic
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
Propulsé par Kunena