Hi Guys,
For an old legacy system we need to print some files from an 2012 server every 10seconds or something. When that is done, i need to move them to another folder.
I found and modified this script below, but when i run the script it does not print, but i move the files and then i get an notepad error that i cannot find the files to print.
Could someone help me please?
dir “C:\temp\Print*.txt” |
ForEach-Object {
$moved = $False
Start-Process -FilePath $.FullName -Verb Print
Do {
Try {
$ |
Move-Item -Destination “C:\temp\Printed” -ErrorAction Stop
$moved = $True
}
Catch {
$moved = $False
Start-Sleep 1
}
} While (!$moved)
}
When i put a start-sleep 5 between start-proces en Do { it works but i get an error message.
Sleep-start : The term ‘Sleep-start’ is not recognized as the name of a cmdlet, function, script file, or operable program. C
heck the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:5 char:5
-
Sleep-start 5
-
~~~~~~~~~~~
- CategoryInfo : ObjectNotFound: (Sleep-start:String) , CommandNotFoundException
- FullyQualifiedErrorId : CommandNotFoundException
There is no such cmdlet called ‘Sleep-start’, hence your error.
The snippet you posted shows the correct command.
Start-Sleep 1
So, I am not sure where this ‘Sleep-start’ is coming from.
You also don’t have a printer destination specified.
For example —
Function Start-PrintTestPage
{
[cmdletbinding()]
[Alias('sptp')]
Param
(
[string]$Printer = "Brother MFC-J985DW Printer"
)
Invoke-CimMethod -MethodName printtestpage `
-InputObject (Get-CimInstance win32_printer -Filter "name LIKE '$printer'")
}