SCCM 2012, PowerShell and Printer Share Creation

Today I wrote a couple of quick PowerShell Scripts to get shared printers from all computers on the domain, and another one to take the data returned and use it in an OSD Task in SCCM 2012 to create the shares printers when we deploy Windows 7.

The first script is as follows

# By Gary Rice
# V1 - 14/05/2013
# Printer information for import needs to be as follows
# $Printers = "HP LaserJet 4250 PCL6","Kyocera FS-1030D KX"
# $Computers = "MININT-HJ0UIN4","MININT-LR30CVS"
# $Sharenames = "MININT-HJ0UIN4-HPLJ4250","MININT-LR30CVS-FS1030D"

$OutPut = ""

$NL = [Environment]::NewLine
$FileName = Get-Date -format "yyyy-MM-dd-HH-mm-ss"
$Filename += ".txt"
$C = ""
$Pstring = "`$Printers = "
$Cstring = "`$Computers = "
$Sstring = "`$Share = "

$OutPut += "Computer,Printer Name,Printer Driver,Printer Share Name" + $NL
$OU = "OU=Desktop Computers,DC=test,DC=internal,DC=snowey,DC=com"
$DomainComputers = Get-ADComputer -SearchBase $OU -Filter `*` | Select-Object -ExpandProperty Name

foreach($Computer in $DomainComputers)
    if(!(Test-Connection -Cn $Computer -BufferSize 16 -Count 1 -ea 0 -quiet))
        $OutPut += $Computer + "," + "Error" + $NL
        $Printers = get-wmiobject -computername $Computer -query "select * from win32_printer"
        foreach ($Printer in $Printers)
            if($Printer.Shared -eq "True")
                $OutPut += $Computer + "," + $ + "," + $Printer.drivername + "," + $Printer.ShareName + $NL
                $Pstring += $C + "`"" + $Printer.drivername + "`""
                $Cstring += $C + "`"" + $Computer + "`""
                $Sstring += $C + "`"" + $Printer.ShareName + "`""
                $C = ","

$FilenameFN ="Computers-Printers-" + $Filename
$Output | Out-File $Env:Temp$FileNameFN
Invoke-Expression $Env:Temp$FileNameFN

$OutPut = $Pstring + $NL + $Cstring + $NL + $Sstring
$FilenameFN ="Computers-printers-OSD-String" + $Filename
$Output | Out-File $Env:Temp$FileNameFN
Invoke-Expression $Env:Temp$FileNameFN

It’s not very complex, it just goes off and gets all the computers in a specific OU, checks that are active then loops through all the printers and if any are shared it saves the computer name, printer driver name and share name to file. I had to use printer driver name as the Printer name was not always accurate or what it should be due to historical renaming.

Then, the script that I included in the OSD Task Sequence was

# By Gary Rice
 # V1.1 - 15/05/2013
 # Uses `Shared Printers on Domain Computers.PS1` to generate data
 # To be run as part of SCCM 2012 OSD Task

$Count = 0
 $Printers = "HP LaserJet 4250 PCL6","Kyocera FS-1030D KX"
 $Computers = "MININT-HJ0UIN4","MININT-LR30CVS"
 $Shares = "MININT-HJ0UIN4-HPLJ4250","MININT-LR30CVS-HPLJ4250"

foreach ($Computer in $Computers)
 if ($Computer -eq $env:computername)
 $TargetPrinters = get-wmiobject -computername $Computers[$count] -query "select * from win32_printer"
 foreach ($Printer in $TargetPrinters)
 if ($ -eq $Printers[$Count])
 $Printer.shared = $true
 $Printer.sharename = $Shares[$Count]
 $Count += 1

Again very simple, it takes an array of computers (printer names and share names) and loops through them until it finds a match. It then loops through all the printers on the local machine until it finds one that matches Printer Driver and then it creates the share.

There might be a different / easier way of doing this, but when you need something quick.

Hopefully someone might find them useful (or not).

Age limit on IT

Today I asked myself as very valid question – “Should there be an age limit on someone using IT equipment?”

This was as a result of a combined call time of 1H 18M to the Silver Fox to get his Netgear TA612V VOIP adapter up and running after I unlocked and flashed it for him.
I was under the impression that I had already configured the Lan and Wan ports to match his subnet and what they needed to be, which would of made a remote session a doddle.

Unfortunately it would appear not! So I tried to add another subnet to his network card so that I could configure it that way but that didn’t want to work either!

Next I asked him to get his laptop out and plug a network cable in the back of the laptop and then in the Ethernet port of the TA612V, that’s the Ethernet port not the Internet port. After clarifying that point a couple more times we had it connected how we wanted it to be.

Things were made even more difficult as the laptop was on the floor and he was sat on the chair and every time he leant down to do something in the laptop he had his deaf ear pointing towards the phone! Could this get any worse?

I got him to check what IP the TA612V had given him, hoping to login and make some changes, only to find that the laptop had a IP address. So I get him to reset the device and wait for it to all come back up and settle down. This time he has the expected IP address, so I get him to logon to the web interface and click on the Wan settings.

I tell him what to put in and then save it. We then wait for it to reboot and then come back up. Next I tell him to go to the Lan interface and enter some more details and save again. I then tell him to plug it back into the network and turn it on.

I then connect to the Lan interface, log on and set up his VOIP connection, save and then let it reboot. It takes a few seconds to come back up and register the VOIP connection with Sipgate.

Great so its all working, I make a test call and the phone rings but there is no voice from me!? I log back in and check the settings. Correct ports entered and the settings match my TA612V that works fine. So I suggested a reboot again and see what it does. Up it comes and registered in a few seconds. I make another call to him and get the same problem.

I then, by pure fluke, click on the Wan settings only to find a few digits missing from the IP address and the Subnet Mask! I correct the errors, save and reboot. Once registered I make a call again and hey presto it all works ok.

I told him what was wrong, and I got in response “I put in exactly what you told me to put in. I would not of thought those being missed off would of caused a problem”

I left it at that, making a mental note to myself to check and double check what settings he puts in for me next time!

Another one fixed

Today I done one of the things that I love doing – helping someone out.

I was given a laptop that was knackered and on it was the users personal and company data. Added to the already stressful situation of it being knackered was the fact that there was no backup of the data! Needless to say, they were not in the best of moods and were way from happy.

The situation reminded me of a time at my old company, where some one else was asked to look at one of the bosses computers. I had previously fixed it twice before so was surprised to not do it again.
Anyhow, I sat and watched not one, not two, not three, not four but five people spend time looking at this computer on and off with each other. It took them all day to get it working, well when I say get it working, they said that they installed a dodgy copy of Windows 7 on it and said it would be much better than the operating system that it had on it before?!?!?
Vista may be many things but it was a legal copy and it had been working fine for several years.
I had to have a laugh to myself, while thinking – Idiots!! Any proper technician would not do that, but then …..

So, back to the problem in hand, several hours later I had managed to get all the important and critical data off of the knackered disk and go about setting the laptop back up again.

Its nice to get a good feeling of helping someone out, while kind of saving their life.

Dumbing it down!

You know, sometimes you really do have to dumb it right down to ID10T level – that im afraid is a lesson that I should have remembered from my old company when I was working with some of the people there.

I guess sometimes I look at things far too technically – for example for the past 4 days I’ve been trying to unlock a TA612V Netgear VOIP adapter as I found a couple on eBay cheap. I suggested to the silver fox that he should get one to replace his dodgy ATA device that has been playing up.

While the TA612V is a old bit of kit, I have had one sat in my comms room linked up to my Sipgate service running with no problems for years.

So, 2 TA612V`s turn up for me to find that they are brand new and locked to Sipgate. Not a problem as that is who I want to use it with. Sadly they no longer support the TA612V and have no config files or L2 passwords for them. OH!
So I spend time looking for a way to unlock them. I went searching for a way to get a L2 password and found a few instructions how to get them. I spend the next 2 days researching and soldering wires on the the pcb to establish a com connection, only to find that I had the wrong cable.

So new cable ordered I thought I would leave it for a bit, but then found a 3rd TA612V in my broadband equipment box, which amazingly was unlocked.

I configured it to use the details of the Silver Fox`s VOIP connection, which took a few tries as it seems the specifics were different from mine. Finally I got it configured and it went off and connected. I tested a phone call but found that I could not hear the other end.

So I changed IP addresses and put it in place of my box and plugged the phone in and turned it on. My firewall was set to point certain traffic to my TA612V so I guess that was the issue. After it connected I made another phone call and got the same problem. So I compared configs to make sure that nothing was different, but they were exactly the same. I then changed the settings back to my account and tried that – still the same problem.

I then put my box back on and let that boot up, only to find that the same problem was happening! How could that be, as I had not changed anything on my TA612V.
So, what the hell was wrong? Maybe the TA612V was blocked as I had been swapping 2 of them around?
I left the TA612V to `settle down` for a few hours but it made no difference!
I left the TA612V off all night but it made no difference!
Maybe my firewall had got confused – rebooted it but no different!

I then spoke to the Silver Fox who told me that his TA612V worked fine, not only could he hear other people and they hear him but he had his working behind his firewall with no ports open??

By this time I had lost the plot and was ready to go back to the fast food industry, when I had a thought – let me try the landline phone on the TA612V instead of the phone i have plugged into it.

The rest you can guess!