Using Powershell 2.0, is it possible to traverse directory and print files on the client-installed printer?
I got the below PowerShell script. It works great over the shared network drive, but how do I actually modify and use it to query the content of WebDav folders and then print only the .PDF file extension on the client side (not the server side)?
PowerShell script to traverse the directory:
function print-file($file) {
begin {
function internal-printfile($thefile) {
if ($thefile -is [string]) {
$filename = $thefile
}
else {
if ($thefile.FullName -is [string] ) {
$filename = $THEfile.FullName
}
}
$start = new-object System.Diagnostics.ProcessStartInfo $filename
$start.Verb = "print"
[System.Diagnostics.Process]::Start($start)
}
if ($file -ne $null) {
$filespecified = $true;
internal-printfile $file
}
}
process {
if (!$filespecified) {
write-Host process ; internal-printfile $_
}
}
}
dir *.pdf -r | print-file
The following command should do the trick – traverse all the files in the directory, get their content and send the content to the current printer. I tested it and it works fine:
It takes all the files from the current folder.