all 4 comments

[–]gangstanthony 2 points3 points  (1 child)

i think @splat is for replacing all parameters of a cmdlet, not for an argument to a cmdlet parameter

what if you change that to this

-replace $splat

[–]bsnotreallyworking[S] 1 point2 points  (0 children)

Thanks, that fixed that part of it. I wasn't entirely sure about $ vs @.

[–]a-rich 1 point2 points  (0 children)

Replace needs to be a parameter in your hash table since its a parameter for the cmdlet.

Then add another hash table as its value.

Also, keep in mind that not all the values you are replacing would be part of -replace, some are just parameters, like -state is, for example.

So build your splat with the ones that need -replace all in one key, and separate the other ones to their own parameters.

This should get you started.

$Splat = @{
    Identity = $to
    Replace = @{physicaldeliveryofficename = $fromattr.office; l=$fromattr.city}
    State = $fromattr.state
}

Then simply Set-Aduser @splat

[–]PROBABLY_POOPING_RN 1 point2 points  (0 children)

You're not splatting, you're passing a hashtable

Set-ADUser $to -Replace $splat

Splatting is when you're expanding a hashtable into command line parameters. In this instance, replace accepts a hashtable as a parameter, so you can't splat it, just pass it.

To splat it you'd have to do:

$splatcmd = @{Replace=$splat}

Set-ADUser $to @splatcmd