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 [strin开发者_如何学JAVAg]) {
$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:
Get-ChildItem . -filter *.* -recurse | get-content | out-printer
It takes all the files from the current folder.
精彩评论