Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Overwrite Parameter in Do loop

$
0
0

When I attempt to run the following function I am unable to overwrite the $nametocheck variable using read-host.  This is passed as a parameter and I want to return it for use in another function. The $mailboxes and $groups are arrays with groups and mailboxes from Office 365.

Function UserGroupCheck
{
param(
		[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
		[string] $nametocheck
	)
    $errorcheck = $error.count

    $mailboxes = get-mailbox
    $groups = Get-group

    
  
    Do{
         $endloop = $false

        
        If($mailboxes -contains $nametocheck){
            $endloop = $true}
        
        ElseIf($groups -contains $nametocheck){
            $endloop = $true}

        If($endloop -ne $true){
        Write-Output "Did you mean one of these?"

        $mailboxes -like "*$nametocheck*"
        $groups -like "*$nametocheck*"
        $nametocheck = Read-Host -Prompt 'Enter the correct name'
        }

    }while ($endloop -ne $true)

  
       If ($errorcheck -lt $error.count)
        {
            Write-Output "There seems to be a problem, Please check the error."
            Write-Output $error
            KeyPause
        } 

  return $nametocheck
}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>