In my script, I'm parsing emails and regex-ing into variables. When i write-host or query the variable it shows, but when I try to run it in the script below it acts lick its empty.
I'm saving the variable as $Branch
$Branch = $Matches.BRANCH
Get-ADOrganizationalUnit -Filter "Name -like '$($Branch)'"
I've tried:(when I run this, it runs with no errors, but also nothing shows.)
Get-ADOrganizationalUnit -Filter 'Name -like $Branch'
when I try this I get an error that actually shows the contents of the variable in the error.
Get-ADOrganizationalUnit -Filter "Name -like "$Branch""
Get-ADOrganizationalUnit : A positional parameter cannot be found that accepts argument 'WA AZ1'.
At line:1 char:1
+ Get-ADOrganizationalUnit -Filter "Name -like "$Branch""
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADOrganizationalUnit], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.GetADOrganizationalUnit
If I manually create the variable and run it, it works and finds the correct OU.
any help would be great, thanks