Hello Guys
in my testdomain.lab, i have following five OUs in mt test AD structure:
'OUusers', 'OUcomputers','OUservers','OUadministrators','OUhelpdesks'.
i have created following five variables:
$OUusers ='ou=OUusers,dc=mytestdomain,dc=lab' $OUcomputers ='ou=OUcomputers,dc=mytestdomain,dc=lab'
and so on
now i have created a function which gets this names as input & foreach-object creates the related OU.
but the problem is sometimes when i run my function, maybe some of those five OUs currently exist in AD so this will cause a terminating error.
so i know i must use switch statement to define conditions like this:
if $OUusers doesn't exist, execute this : new-ADOrganizationalunit $OUusers
if $OUcomputers doesn't exist, execute this : new-ADOrganizationalunit $OUcomputers
and so on...
it's a long time which i am trying to create a function which contains such switch statement & properly forEach-object loop.
i have studied switch and foreach-object loops , but this scenario is complicated for me & i was unable to get the correct code.
Function createOUs {# combination of ForEach-Object and Switch statement here}
may someone give me the correct command please?
thanks a lot