Skip to content

If


Example 1

    #----------------------------------------------#
    # Validate manager exists
    #----------------------------------------------#
    Start-Sleep -s 1
    $Manager = Get-ADUser $tbManager.Text

    # If the manager exists in AD then write a confirmation message to the rick text box
    If ($Manager | where-object { $_.SamAccountName -eq $tbManager.Text })
    {
        $rtbInformation.SelectionColor = 'green'
        $rtbInformation.AppendText("Validation check for manager has passed.`r")
        $rtbInformation.AppendText("`n")
    }
    # If the manager is not found then write a failure message and break the script
    Else
    {
        $rtbInformation.SelectionColor = 'red'
        $rtbInformation.AppendText("ERROR: The manager does not exist, please check and run creation again.")
        $rtbInformation.AppendText("`n")
        start-sleep -Seconds 2
        enablebuttons
        Return
}

Example 2

    if (Get-ADUser -Identity $tbUsername.text | Where-Object { $_.SamAccountName -eq $tbUsername.Text })
    {
        $richtextbox1.SelectionColor = 'Green'
        $richtextbox1.AppendText("User created successfully")
        $richtextbox1.AppendText("`n")
    }
    Else
    {
        $richtextbox1.SelectionColor = 'Red'
        $richtextbox1.AppendText("User not created")
        $richtextbox1.AppendText("`n")
    }