0

how can I pass the $var2 in to the invoke script, if I do it like this, the script will write the '$var2' into the feild instead of the context auf the $var2. I cant remember, there is a way to special mark the $var or how can I do this? many thanks

$var1 = 'CN=user1,OU=_Test,DC=test,DC=de'
$var2 = 'test123'

$argsArray = @()
$argsArray += $var1
$argsArray += $var2


$s = New-PSSession -computerName localhost -credential $credential -Authentication Credssp

$out = Invoke-Command  -Session $s -Argumentlist $argsArray -ScriptBlock {

param($var1,$var2)

#load-Module -Name ActiveDirectory

Get-ADObject -Filter "ObjectCategory -eq 'person'" -SearchBase „DC=test,DC=de“ -Properties description, displayName |  
Where-Object {($_.DistinguishedName -like "$var1")}  | set-ADObject -Add @{'msExchExtensionAttribute39'='$var2'} 



} #ScriptBlock
vespavbb
  • 11
  • 6
  • 2
    You're already passing `$var2` it's just that your use of single quotes is not allowing the expansion of the varaible. `'$var2'` => `$var2` – Santiago Squarzon Mar 07 '22 at 13:03

0 Answers0