Goal here was to dial in to the work place VPN, map network drives (the user has access to), map the printers the user has access.
This is my first attempt at writing a script in Powershell, I am no programmer, I have little to very less knowledge about how to remember syntax, use the logic etc. I wrote this little script using help from various sources and then tweaked it to achieve what I set out to.
The script begins after this line: -
#region main script
#Prompts for Credential and stores it in a variable.
#This piece of the script dials your VPN connection, based on the credentials supplied. Note your supplied credentials should have access to use VPN.
$credential = $host.UI.PromptForCredential("AnyName", "Please enter your domain User name and password to connect to the VPN", "", "domainname")
rasdial "VPN Connection" $credential.GetNetworkCredential().UserName $credential.GetNetworkCredential().Password
#Maps the network drives
$objNet = New-Object -ComObject WScript.Network
$objNet.MapNetworkDrive("H:", "\\servername\sharename\" + $credential.GetNetworkCredential().UserName, $false, $credential.UserName, $credential.GetNetworkCredential().Password)
$objNet.MapNetworkDrive("V:","\\servername\sharename")
$objNet.MapNetworkDrive("G:","\\servername\sharename")
$objNet.MapNetworkDrive("K:","\\servername\sharename")
$objNet.MapNetworkDrive("", "\\printservername\ipc$", $false, $credential.UserName, $credential.GetNetworkCredential().Password) #for mapping IPC$ to ensure printers get mapped.
# Maps the Printer. Remember we need to pass the credentials to be able to map the printers. So we use the IPC$ to use the credentials already supplied.
#Main Script
$PrinterPath = "\\printservername\printersharename"
$net = new-Object -com WScript.Network
$net.AddWindowsPrinterConnection($PrinterPath)
$PrinterPath1 = "\\printservername\printersharename"
$net1 = New-Object -com WScript.Network
$net1.AddWindowsPrinterConnection($PrinterPath1)
$PrinterPath2 = "\\printservername\printersharename"
$net2 = New-Object -com WScript.Network
$net2.AddWindowsPrinterConnection($PrinterPath2)
End of Script.
This book has been a guide for me to get to know about the basics of Powershell 2.0
2 comments:
Thank you for sharing this script it worked with network.
us vpn
hey thanks for the feedback, glad to help :-)
Post a Comment