Friday 25 July 2014

Powershell script to add printers from CSV and adjust driver

If you find yourself needing to do a printer migration but cant/don't want to re-install the old drivers (e.g. a cross architecture migration), you can import your printers from a .csv and change the driver as needed:
 
CSV Format:


Printserver,drivername,PortName,IPAddress,Sharename,Location,Comment,Printername
XXX,HP Test,IP_x.x.x.x,x.x.x.x,printername,location test,comment test,printername

Script:


function CreatePrinter {

$server = $args[0]

$print = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_Printer").createInstance()

$print.drivername = $args[1]

$print.PortName = $args[2]

$print.Shared = $true

$print.Sharename = $args[3]

$print.Location = $args[4]

$print.Comment = $args[5]

$print.DeviceID = $args[6]

$print.Put()

}

function CreatePrinterPort {

$server = $args[0]

$port = ([WMICLASS]"\\$server\ROOT\cimv2:Win32_TCPIPPrinterPort").createInstance()

$port.Name= $args[1]

$port.SNMPEnabled=$false

$port.Protocol=1

$port.HostAddress= $args[2]

$port.Put()

}

 

 

$printers = Import-Csv c:\printers.csv

foreach ($printer in $printers) {

CreatePrinterPort $printer.Printserver $printer.Portname $printer.IPAddress

CreatePrinter $printer.Printserver $printer.drivername $printer.Portname $printer.Sharename $printer.Location $printer.Comment $printer.Printername

}

Wednesday 23 July 2014

VBScript to automatically map PST files into Outlook


Edit Set objFolder = objFSO.GetFolder("H:\PST")to suit your requirements:

**********************

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objnet = CreateObject("wscript.network")

Set olkApp = CreateObject("Outlook.Application")

Set objFolder = objFSO.GetFolder("H:\PST")

For Each objFile In objFolder.Files

   If LCase(objFSO.GetExtensionName(objFile.Name)) = "pst" Then

     olkApp.Session.AddStore objFile.Path

   End If

Next

Sunday 13 July 2014

Extract data from Offline Files Client Side Cache (CSC) using CSCCMD

On a XP or 2003 machine:

Download CSCCMD 1.1 

Run the following:

csccmd /isenabled

csccmd /disable

Use the following reg key to set an alternate location for the database to be restored:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\NetCache\DatabaseLocation

String = c:\CSCFiles

Disable NIC 

csccmd /enable

csccmd /enum

csccmd /extract /target:PathWhereToPutExtractedFiles /recurse

Wednesday 30 April 2014

Simple powershell robocopy log analyser


Select-String -path "\\server\share\logfile.log" -pattern "Access Is Denied" -allm

atches -simplematch -context 1 | out-file '\\server\share\errors.log'