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
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
add a comment |
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
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
add a comment |
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
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
powershell automation printers
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
Select-Object
will create a PSCustomObject
of key/values. I'd recommend two options:
- Use
ExpandProperty
to return only the value ofsharename
. i.e.... | select -expandproperty sharename
. - 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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Select-Object
will create a PSCustomObject
of key/values. I'd recommend two options:
- Use
ExpandProperty
to return only the value ofsharename
. i.e.... | select -expandproperty sharename
. - 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.
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
add a comment |
Select-Object
will create a PSCustomObject
of key/values. I'd recommend two options:
- Use
ExpandProperty
to return only the value ofsharename
. i.e.... | select -expandproperty sharename
. - 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.
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
add a comment |
Select-Object
will create a PSCustomObject
of key/values. I'd recommend two options:
- Use
ExpandProperty
to return only the value ofsharename
. i.e.... | select -expandproperty sharename
. - 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.
Select-Object
will create a PSCustomObject
of key/values. I'd recommend two options:
- Use
ExpandProperty
to return only the value ofsharename
. i.e.... | select -expandproperty sharename
. - 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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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