tommej Posted October 14, 2011 Posted October 14, 2011 (edited) Hi All, I'm having a lot of trouble getting terminal services to map printers! Below is the script we're using along with some debug stuff which was supposed to help us. Dim LeftString, netPrinter Set Sh = CreateObject("WScript.Shell") sys = Sh.ExpandEnvironmentStrings("%CLIENTNAME%") LeftString = Left(sys, 3) if leftstring = "HP0" OR leftString = "IEC" then Set netPrinter = CreateObject("WScript.Network") netPrinter.AddWindowsPrinterConnection "\\printserver\printer" netPrinter.SetDefaultPrinter("\\printserver\printer") else wscript.echo "Debug, client name: " & sys end if Now the problem occurs when we use the script fro GPO as a login script. Upon login I get a popup with "Debug, Client name: %clientname%". BUT! If I run the script manually, from an interactive session, it behaves as expected by either mapping the printer, or giving the debug message displaying the clientname correctly. Any ideas? Edited October 14, 2011 by tommej
mavhc Posted October 15, 2011 Posted October 15, 2011 Maybe the variable doesn't exist at that point, can you get a list of environment variables and see? I wanted to map printers due to IP, so used GETTSCIP.exe and Set WshShell = wscript.CreateObject("WScript.Shell") Set oExec = WshShell.exec("gettscip.exe") sOutput = oExec.StdOut.ReadLine sOutput = Mid(sOutput, 19, len(sOutput)-18) iparray = split(sOutput,".") location = CInt(iparray(2)) select case location case 58 base = "a" case 59 base = "b" case 60 base = "c" case 61 base = "d" case else base = CStr(location) end select GetTSCIP = base End Function
FN-GM Posted October 16, 2011 Posted October 16, 2011 I have used this in the past, works well - Printer Addition Based on Location - Wiki
TheScarfedOne Posted October 16, 2011 Posted October 16, 2011 Im going to do a blog post on Printer Mapping with RDS - as Ive just completed a bit project with it. Learnt a hell of a lot, and its taken 3 weeks to get it right. Will update this when I post it.
tommej Posted October 17, 2011 Author Posted October 17, 2011 Hi Tommej, Are you using 2008R2 RDS? Just regular old 2008
BHMS Posted October 17, 2011 Posted October 17, 2011 You can use group policy preferences with terminal services targeting to deploy printers to specific TS clientnames. I use this for 2008 R2 but it required a hotfix before it would work.
tommej Posted October 17, 2011 Author Posted October 17, 2011 For now I think I have sorted this using powershell and the PSTerminalServices module Import-Module PSTerminalServices $result = Get-TSSession -Filter {$_.Username -like [Environment]::Username} | Select-Object ClientName -expandproperty ClientName $printServer = "\\printerserver\" if ($result.contains('IEC')) { $printer = New-Object -ComObject WScript.Network $printer.AddWindowsPrinterConnection($printServer + "printername") $printer.SetDefaultPrinter($printServer + "printername") } if ($result.contains('HP0')) { $printer = New-Object -ComObject WScript.Network $printer.AddWindowsPrinterConnection($printServer + "printername") $printer.SetDefaultPrinter($printServer + "printername") } if ($result.contains('whatever')) { $printer = New-Object -ComObject WScript.Network $printer.AddWindowsPrinterConnection($printServer + "printername") $printer.SetDefaultPrinter($printServer + "printername") }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now