2012-05-27 19 views
0

我不是很熟悉PowerShell腳本,我被困在這個問題: 我需要在這樣的檢索對象的一些操作:致電[ADSI]與外部參數

$object = [ADSI]'LDAP://CN=Test User,OU=Dept,OU=Users,DC=example,DC=org' 
... 
$object.Commit() 

能正常工作,但我必須使用存儲在變量專有名稱 - 我的測試腳本看起來是這樣,但它不工作:

$object = [ADSI]'LDAP://$variable' 
... 
$object.Commit() 

第一次調用[ADSI]本身不會造成錯誤,但任何後續操作與崩潰消息:

The following exception occurred while retrieving member "commit": "The server is not operational. 
" 
At line:1 char:10 
+ $object.commit <<<<() 
+ CategoryInfo   : NotSpecified: (:) [], ExtendedTypeSystemException 
+ FullyQualifiedErrorId : CatchFromBaseGetMember 

我很確定,參數是以某種錯誤的方式發送的,但我不知道,如何解決它,任何人都可以幫忙?

tahnks

回答

5

嘗試:

$object = [ADSI]"LDAP://$variable" 

單引號不擴展變量。