Get Default Printer ShareName w/ Powershell in VariableSetting Windows PowerShell path variableDetermine installed PowerShell versionPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?Keep old default printer name on new print serverPowershell: Adding printers to printserverUse Powershell to set Print Spooled Documents FirstPowershell printer installation scriptProcessBuilder removes " from the command in powershellNeed to get file info before it will be printed using PowerShell

Can someone clarify Hamming's notion of important problems in relation to modern academia?

Knowledge-based authentication using Domain-driven Design in C#

How exploitable/balanced is this homebrew spell: Spell Permanency?

Car headlights in a world without electricity

Does the Cone of Cold spell freeze water?

Finding the error in an argument

Is it inappropriate for a student to attend their mentor's dissertation defense?

ssTTsSTtRrriinInnnnNNNIiinngg

How can saying a song's name be a copyright violation?

Getting extremely large arrows with tikzcd

What are the G forces leaving Earth orbit?

How dangerous is XSS

Unlock My Phone! February 2018

Mathematica command that allows it to read my intentions

Is it possible to map the firing of neurons in the human brain so as to stimulate artificial memories in someone else?

What is the opposite of "eschatology"?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

Was the old ablative pronoun "med" or "mēd"?

Is it a bad idea to plug the other end of ESD strap to wall ground?

How to travel to Japan while expressing milk?

Fair gambler's ruin problem intuition

Why didn't Boeing produce its own regional jet?

What exactly is ineptocracy?

What's the meaning of "Sollensaussagen"?



Get Default Printer ShareName w/ Powershell in Variable


Setting Windows PowerShell path variableDetermine installed PowerShell versionPowerShell says “execution of scripts is disabled on this system.”How do you comment out code in PowerShell?Keep old default printer name on new print serverPowershell: Adding printers to printserverUse Powershell to set Print Spooled Documents FirstPowershell printer installation scriptProcessBuilder removes " from the command in powershellNeed to get file info before it will be printed using PowerShell













1















I'm trying to store the current default printer in a variable in Powershell to add this name back using a different print server. The command I'm using to store this name is:



$default_printer = Get-WMIObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | where$_.Name -like "*\*" | select sharename


Which will provide me with:



sharename
---------
WI_IT-Test


Issue arises when I try and setup the new printer with the command:



Add-Printer -ConnectionName \printsrv01$default_printer


I believe when I'm setting the variable in the beginning it's also storing the string " sharename --------- " as well as the name of the Printer.
How do I only grab the printer name and not the...



sharename
---------


Any help would be appreciated!










share|improve this question






















  • I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

    – hsimah
    Mar 22 at 0:06
















1















I'm trying to store the current default printer in a variable in Powershell to add this name back using a different print server. The command I'm using to store this name is:



$default_printer = Get-WMIObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | where$_.Name -like "*\*" | select sharename


Which will provide me with:



sharename
---------
WI_IT-Test


Issue arises when I try and setup the new printer with the command:



Add-Printer -ConnectionName \printsrv01$default_printer


I believe when I'm setting the variable in the beginning it's also storing the string " sharename --------- " as well as the name of the Printer.
How do I only grab the printer name and not the...



sharename
---------


Any help would be appreciated!










share|improve this question






















  • I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

    – hsimah
    Mar 22 at 0:06














1












1








1








I'm trying to store the current default printer in a variable in Powershell to add this name back using a different print server. The command I'm using to store this name is:



$default_printer = Get-WMIObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | where$_.Name -like "*\*" | select sharename


Which will provide me with:



sharename
---------
WI_IT-Test


Issue arises when I try and setup the new printer with the command:



Add-Printer -ConnectionName \printsrv01$default_printer


I believe when I'm setting the variable in the beginning it's also storing the string " sharename --------- " as well as the name of the Printer.
How do I only grab the printer name and not the...



sharename
---------


Any help would be appreciated!










share|improve this question














I'm trying to store the current default printer in a variable in Powershell to add this name back using a different print server. The command I'm using to store this name is:



$default_printer = Get-WMIObject -Query " SELECT * FROM Win32_Printer WHERE Default=$true" | where$_.Name -like "*\*" | select sharename


Which will provide me with:



sharename
---------
WI_IT-Test


Issue arises when I try and setup the new printer with the command:



Add-Printer -ConnectionName \printsrv01$default_printer


I believe when I'm setting the variable in the beginning it's also storing the string " sharename --------- " as well as the name of the Printer.
How do I only grab the printer name and not the...



sharename
---------


Any help would be appreciated!







powershell automation printers






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 21 at 20:40









generogenero

102




102












  • I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

    – hsimah
    Mar 22 at 0:06


















  • I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

    – hsimah
    Mar 22 at 0:06

















I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

– hsimah
Mar 22 at 0:06






I think you are wanting to use the -ExpandProperty parameter when selecting. This selects the value only and not the key/value object. i.e. ... | select -ExpandProperty sharename.

– hsimah
Mar 22 at 0:06













1 Answer
1






active

oldest

votes


















0














Select-Object will create a PSCustomObject of key/values. I'd recommend two options:



  1. Use ExpandProperty to return only the value of sharename. i.e. ... | select -expandproperty sharename.

  2. the sharename property. i.e. Add-Printer -ConnectionName "\printsrv01$($default_printer.sharename)"

In your case you're wanting a single property so the first option is good. If you are selecting multiple properties the latter is the way to go.






share|improve this answer


















  • 1





    Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

    – genero
    Mar 27 at 16:03











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288914%2fget-default-printer-sharename-w-powershell-in-variable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Select-Object will create a PSCustomObject of key/values. I'd recommend two options:



  1. Use ExpandProperty to return only the value of sharename. i.e. ... | select -expandproperty sharename.

  2. the sharename property. i.e. Add-Printer -ConnectionName "\printsrv01$($default_printer.sharename)"

In your case you're wanting a single property so the first option is good. If you are selecting multiple properties the latter is the way to go.






share|improve this answer


















  • 1





    Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

    – genero
    Mar 27 at 16:03















0














Select-Object will create a PSCustomObject of key/values. I'd recommend two options:



  1. Use ExpandProperty to return only the value of sharename. i.e. ... | select -expandproperty sharename.

  2. the sharename property. i.e. Add-Printer -ConnectionName "\printsrv01$($default_printer.sharename)"

In your case you're wanting a single property so the first option is good. If you are selecting multiple properties the latter is the way to go.






share|improve this answer


















  • 1





    Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

    – genero
    Mar 27 at 16:03













0












0








0







Select-Object will create a PSCustomObject of key/values. I'd recommend two options:



  1. Use ExpandProperty to return only the value of sharename. i.e. ... | select -expandproperty sharename.

  2. the sharename property. i.e. Add-Printer -ConnectionName "\printsrv01$($default_printer.sharename)"

In your case you're wanting a single property so the first option is good. If you are selecting multiple properties the latter is the way to go.






share|improve this answer













Select-Object will create a PSCustomObject of key/values. I'd recommend two options:



  1. Use ExpandProperty to return only the value of sharename. i.e. ... | select -expandproperty sharename.

  2. the sharename property. i.e. Add-Printer -ConnectionName "\printsrv01$($default_printer.sharename)"

In your case you're wanting a single property so the first option is good. If you are selecting multiple properties the latter is the way to go.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 1:00









hsimahhsimah

4981024




4981024







  • 1





    Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

    – genero
    Mar 27 at 16:03












  • 1





    Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

    – genero
    Mar 27 at 16:03







1




1





Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

– genero
Mar 27 at 16:03





Thank you. The "\printsrv01$($default_printer.sharename)" minus the quotes was the trick in this case. :) Thanks again!

– genero
Mar 27 at 16:03



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288914%2fget-default-printer-sharename-w-powershell-in-variable%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?