I am writing a script where a part of it needs to connect to domain controller and get all the gpo's currently linked to a specific OU. the line that does that is:
Invoke-Command -Session $S -ScriptBlock {Get-GPInheritance -target $using:Switch -domain shahar.local -server dc01 }
$s= credentials, $switch is a a variable that contains an ou that was picked. those variables exists and they are good. the error i get is:
Value does not fall within the expected range. + CategoryInfo : NotSpecified: (:) [Get-GPInheritance], ArgumentException + FullyQualifiedErrorId : System.ArgumentException,Microsoft.GroupPolicy.Commands.GetGPInheritanceCommand + PSComputerName : DC01
can anyone please assist?
I'm posting this as answer, because IMO there are too many questions that remain 'unanswered' while the solution is given in a comment.
The error message triggered me to check if any of the variables you use perhaps is an Automatic variable and in this case it is the variable $switch
.
Using a different self-defined variable name here like $selectedOU
should solve the problem.