Wednesday, June 29, 2011
Unblock & Streams
A look at how to unblock files and the use of streams in NTFS, although streaming is an old feature in NTFS, Powershell puts a new perspective on things.
http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/02/scripting-wife-learns-about-unblocking-files-in-powershell.aspx
http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/02/scripting-wife-learns-about-unblocking-files-in-powershell.aspx
Tuesday, June 28, 2011
VPN using Powershell
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
Subscribe to:
Posts (Atom)
#PowerShell HELP
PowerShell has one of the best help database built in to it, well it still has a long way to go to catch up with the Linux Man pages but yo...
-
This song reminds me of how life can truly hurt you, I know life is one of the rarest gift, but it also comes with its own trials and tribul...
-
I wanted to know how to display a list of open applications using Power Shell. Bit of tinkering was not helping me and I was running in t...