Create PSDrive with If and Elseifs


hi

i'm trying create script take text entered , use create psdrive required domain , change psdrive.    i'm trying use if , elseif commands instead of going next if statement hits first statement , thats it, psdrive domain1 created regardless of input.  can help?

$domain = read-host "what domain want change groups in?"
$drivename = read-host "what want call drive?"
if ($domain = "domain1")

new-psdrive -name $drivename -psprovider activedirectory -server "$domain" -credential (get-credential "$domain\administrator") -root "//rootdse/" -scope global
}
    elseif ($domain = "domain2")
{
new-psdrive -name $drivename -psprovider activedirectory -server "$domain" -credential (get-credential "$domain\administrator") -root "//rootdse/" -scope global
}
cd ("$drivename" +":" )

you need change = -eq - 

$domain = read-host "what domain want change groups in?" $drivename = read-host "what want call drive?" if ($domain -eq "domain1") {  new-psdrive -name $drivename -psprovider activedirectory -server "$domain" -credential (get-credential "$domain\administrator") -root "//rootdse/" -scope global }     elseif ($domain -eq "domain2") { new-psdrive -name $drivename -psprovider activedirectory -server "$domain" -credential (get-credential "$domain\administrator") -root "//rootdse/" -scope global } cd ("$drivename" +":" )


[string](0..21 | % {([char][int](22+
("5275778524449275827587
42505554247789249585").substring(($_*2),2)))})`
-replace " "

linkedin:   

note: posts provided “as is” without warranty of kind, either expressed or implied, including not limited implied warranties of merchantability and/or fitness particular purpose.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS