Forum Discussion
mfranhind115
Jul 21, 2022Brass Contributor
how to "parameterize" a for loop cycle
Hi all,
weird question it is.
I would like to change the "for each" loop depending on a value got on input.
This is what I'm trying:
$currdomain = Read-Host "Please enter the name of the domain (i.e.: mydomain.com). Leave it empty for ALL domains"
if (!$currdomain) {
#IF the input value is null, I would cycle on all the domains:
foreach ($user in Get-MsolUser -All | Sort-Object UserPrincipalName) {
} else {
#otherwise only on the domain got as input
foreach ($user in Get-MsolUser -DomainName $currdomain | Sort-Object UserPrincipalName) {
#HERE the body of the cycle
}
any chances to do this?
thanks
mf
You can try the following
foreach ($user in (Get-MsolUser -DomainName $currdomain)) {......}
- farismalaebSteel Contributor
You can try the following
foreach ($user in (Get-MsolUser -DomainName $currdomain)) {......}
- mfranhind115Brass Contributorexcellent farismalaeb!
it works fine!!!
many thanks!