Printing with Powershell

I just introduced a new feature in one of my bots that allows the user to select what printer they would like to use. If the user selects a printer that has spaces in it the bot errors out and says the following.

A screenshot of the printer is below it is called “\Hcs05rf01\KONICA MINOLTA PRINT ROOM”

What can I do to stop this error from happening?

Main.xaml (14.6 KB)

Give a try by Surrounding the printername

String.Format("Start-Process '{0}' '-Verb PrintTo '{1}' ",  CurrentFile.FullName,  MyPrinterName  )

Your code does work when there are no spaces

Is it because I need the printername in Quotes and my variable isn’t doing that?


You can add the quotes to the string like this

Str = """" + str + """"

This will add double wuotes to the string here str is the string variable


we started with single quotes and can use double quotes by escaping with another double quote as mentioned by @Anil_G

here we can use the String.Format method as introduced above and it could look like this:

String.Format("Start-Process '{0}' '-Verb PrintTo ""{1}"" ",  CurrentFile.FullName,  MyPrinterName  )

or with ending / concatenating, where do see 3 double quotes (1 for the escaping, 1 the doublequote, 1 for the string end / start

However just explore what is needed by prototyping the hardcoded command, then port it to the preferred option

This worked great :slight_smile: My final script was
String.Format(“Start-Process '” + CurrentFile.FullName + “’ -Verb PrintTo " + “””" + MyPrinterName + “”“”)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.