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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript