Im trying to do an invoke command inside a function, but having difficulty getting defined variables to pass through.
function Set-RemoteLocalAdmin {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]$ComputerName,
[String] $UserId
)
$sb = {
param($userid)
add-LocalGroupMember -Group "Administrators" -Member "$UserId"}
Invoke-Command -ComputerName $ComputerName -Scriptblock $sb -argumentlist $userid
}
Errors: The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. + CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : COMPUTERNAME-1
The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. + CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException + PSComputerName : COMPUTERNAME-1
Member BUILTIN\ was not found in group Administrators. + CategoryInfo : ObjectNotFound: (BUILTIN:String) [Add-LocalGroupMember], MemberNotFoundException + FullyQualifiedErrorId : MemberNotFound,Microsoft.PowerShell.Commands.AddLocalGroupMemberCommand + PSComputerName : COMPUTERNAME-1
What am I missing here?
Thanks in advance.