Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

LDAP authentication to another domain in Powershell 3.0

$
0
0

I am writing a script to map drives on domain B when the user is using a PC on domain A. The script works fine until I add validation to it. I am thinking the problem may be within the context of the way I am using [ADSI] "LDAP://"
If I take out the if statement with validation it works fine, but if a user enters the wrong password the rest of the script just runs anyway, so that is why I want the credentials screen to come back up if they enter the wrong password. Is there an easier way to do this?

Thanks!

$creds = Get-Credential -user nursing\ -Message "********    Enter Your Nursing Credentials    ********"

$CurrentDomain = [ADSI]“LDAP://OU=mine,DC=nursing,DC=someschool,DC=edu”
$dom = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password)

if ($dom.name -eq $null)
{
    Do
        {
        write-host "Failed to authenticate. Make sure that you have supplied correct username and password."
        $Creds = Get-Credential -user nursing\ -Message "********    Enter Your Nursing Credentials    ********"
        }
    Until ($dom.Name -ne $null)
    }
else
    {
     write-host "Successfully authenticated and connect to domain"
    }

$drive = $(New-Object -Com WScript.Network)
$drive.MapNetworkDrive("H:","\\myserver\home",0,$creds.UserName,$creds.GetNetworkCredential().Password)


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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