2017-09-06 22 views
0

在我的腳本中,我想讓Exchange Online分發組成員加入我的數組$members_idInvoke-Command的問題

我想在遠程服務器上運行該cmdlet Get-DistributionGroupMember所以它看起來是這樣的:

Invoke-Command -Session $Session -ScriptBlock { 
    $members_id = Get-DistributionGroupMember -Identity "power_shell_test" 
} -ArgumentList $members_id 

運行此之後,我得到一個錯誤:

The syntax is not supported by this runspace. This can occur if the runspace is in no-language mode.

image

當我刪除$members_id =它運行良好。

請告訴我,如果你有一個想法,它爲什麼這樣工作。

+0

我會說「與調用命令的問題「是不是一個有意義的標題... – Clijsters

回答

3

我不明白爲什麼你得到錯誤(這是你如何打開$Session可能是因爲),但如果你想遠程命令Get-DistributionGroupMember的在一個局部變量輸出$members_id你需要改變你的代碼對這樣的事情:

$members_id = Invoke-Command -Session $Session -ScriptBlock { 
    Get-DistributionGroupMember -Identity "power_shell_test" 
} 

使用-ArgumentList只有當你想通過其成員你想拆分成腳本塊組的ID:

$members_id = Invoke-Command -Session $Session -ScriptBlock { 
    Param($id) 
    Get-DistributionGroupMember -Identity $id 
} -ArgumentList $group_id 
+0

謝謝你的人,它的作品! –