Converting object to a string
I have a parameter set up to allow me to display outputs to my tool:
Function LogWrite
{
#This function takes the passed text and adds it to the on screen log and the external log file
Param ([string]$logstring)
#Get current date and time
$now = Get-Date -Format g
#Write to screeen
$txb_logs.Appendtext("------------------------------------------------------------------------------ `r`n")
$txb_logs.Appendtext("$now - $logstring `r`n")
}
I want to convert the below to a string?
$StartUp = Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption
Any suggestions?
powershell
add a comment |
I have a parameter set up to allow me to display outputs to my tool:
Function LogWrite
{
#This function takes the passed text and adds it to the on screen log and the external log file
Param ([string]$logstring)
#Get current date and time
$now = Get-Date -Format g
#Write to screeen
$txb_logs.Appendtext("------------------------------------------------------------------------------ `r`n")
$txb_logs.Appendtext("$now - $logstring `r`n")
}
I want to convert the below to a string?
$StartUp = Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption
Any suggestions?
powershell
2
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?
– Tomalak
Nov 16 '18 at 8:50
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
2
... | Select Caption
->... | Select Caption | Out-String
?
– Ansgar Wiechers
Nov 16 '18 at 9:17
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42
add a comment |
I have a parameter set up to allow me to display outputs to my tool:
Function LogWrite
{
#This function takes the passed text and adds it to the on screen log and the external log file
Param ([string]$logstring)
#Get current date and time
$now = Get-Date -Format g
#Write to screeen
$txb_logs.Appendtext("------------------------------------------------------------------------------ `r`n")
$txb_logs.Appendtext("$now - $logstring `r`n")
}
I want to convert the below to a string?
$StartUp = Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption
Any suggestions?
powershell
I have a parameter set up to allow me to display outputs to my tool:
Function LogWrite
{
#This function takes the passed text and adds it to the on screen log and the external log file
Param ([string]$logstring)
#Get current date and time
$now = Get-Date -Format g
#Write to screeen
$txb_logs.Appendtext("------------------------------------------------------------------------------ `r`n")
$txb_logs.Appendtext("$now - $logstring `r`n")
}
I want to convert the below to a string?
$StartUp = Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption
Any suggestions?
powershell
powershell
edited Nov 16 '18 at 8:48
Tomalak
261k52434550
261k52434550
asked Nov 16 '18 at 8:42
Adam Adam
144
144
2
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?
– Tomalak
Nov 16 '18 at 8:50
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
2
... | Select Caption
->... | Select Caption | Out-String
?
– Ansgar Wiechers
Nov 16 '18 at 9:17
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42
add a comment |
2
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?
– Tomalak
Nov 16 '18 at 8:50
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
2
... | Select Caption
->... | Select Caption | Out-String
?
– Ansgar Wiechers
Nov 16 '18 at 9:17
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42
2
2
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?– Tomalak
Nov 16 '18 at 8:50
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?– Tomalak
Nov 16 '18 at 8:50
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
2
2
... | Select Caption
-> ... | Select Caption | Out-String
?– Ansgar Wiechers
Nov 16 '18 at 9:17
... | Select Caption
-> ... | Select Caption | Out-String
?– Ansgar Wiechers
Nov 16 '18 at 9:17
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42
add a comment |
2 Answers
2
active
oldest
votes
I just what it to return the caption column with every item to a new line
You could convert it to CSV, this would have that effect. Column name in the first line, then every item on a new line. This would adapt to any input, so you're free to select more columns, or different objects entirely.
Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption | ConvertTo-CSV -NoTypeInformation
With a slight modification, the logging function can accommodate multi-line inputs:
$logstring | ForEach-Object { $txb_logs.Appendtext("$now - $_`r`n") }
You can also play around with Format-Table
instead of ConvertTo-CSV
.
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it:Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e".$_
refers to the current item.
– Tomalak
Nov 16 '18 at 10:22
add a comment |
$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string
$Startup.gettype() #This will get you the variable type.
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%2f53334207%2fconverting-object-to-a-string%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I just what it to return the caption column with every item to a new line
You could convert it to CSV, this would have that effect. Column name in the first line, then every item on a new line. This would adapt to any input, so you're free to select more columns, or different objects entirely.
Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption | ConvertTo-CSV -NoTypeInformation
With a slight modification, the logging function can accommodate multi-line inputs:
$logstring | ForEach-Object { $txb_logs.Appendtext("$now - $_`r`n") }
You can also play around with Format-Table
instead of ConvertTo-CSV
.
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it:Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e".$_
refers to the current item.
– Tomalak
Nov 16 '18 at 10:22
add a comment |
I just what it to return the caption column with every item to a new line
You could convert it to CSV, this would have that effect. Column name in the first line, then every item on a new line. This would adapt to any input, so you're free to select more columns, or different objects entirely.
Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption | ConvertTo-CSV -NoTypeInformation
With a slight modification, the logging function can accommodate multi-line inputs:
$logstring | ForEach-Object { $txb_logs.Appendtext("$now - $_`r`n") }
You can also play around with Format-Table
instead of ConvertTo-CSV
.
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it:Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e".$_
refers to the current item.
– Tomalak
Nov 16 '18 at 10:22
add a comment |
I just what it to return the caption column with every item to a new line
You could convert it to CSV, this would have that effect. Column name in the first line, then every item on a new line. This would adapt to any input, so you're free to select more columns, or different objects entirely.
Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption | ConvertTo-CSV -NoTypeInformation
With a slight modification, the logging function can accommodate multi-line inputs:
$logstring | ForEach-Object { $txb_logs.Appendtext("$now - $_`r`n") }
You can also play around with Format-Table
instead of ConvertTo-CSV
.
I just what it to return the caption column with every item to a new line
You could convert it to CSV, this would have that effect. Column name in the first line, then every item on a new line. This would adapt to any input, so you're free to select more columns, or different objects entirely.
Get-WmiObject Win32_StartupCommand -ComputerName $ComputerName | Select Caption | ConvertTo-CSV -NoTypeInformation
With a slight modification, the logging function can accommodate multi-line inputs:
$logstring | ForEach-Object { $txb_logs.Appendtext("$now - $_`r`n") }
You can also play around with Format-Table
instead of ConvertTo-CSV
.
answered Nov 16 '18 at 9:17
TomalakTomalak
261k52434550
261k52434550
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it:Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e".$_
refers to the current item.
– Tomalak
Nov 16 '18 at 10:22
add a comment |
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it:Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e".$_
refers to the current item.
– Tomalak
Nov 16 '18 at 10:22
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
thank you this was also very helpful, i will play around this this, by any chance can i change the name caption when it is displayed to my log field
– Adam
Nov 16 '18 at 9:43
You can -
Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it: Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e". $_
refers to the current item.– Tomalak
Nov 16 '18 at 10:22
You can -
Select
accepts two kinds of parameters. Either (a list if) property names (Select Caption
) or little scripts that calculate values dynamically. Scripts consist of a name and an expression. The name becomes the new "column header", the expression can be anything at all - as simple or complex as you need it: Select @{name="New Property"; expression={$_.Caption} }
. "name" and "expression" can be abbreviated to "n" and "e". $_
refers to the current item.– Tomalak
Nov 16 '18 at 10:22
add a comment |
$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string
$Startup.gettype() #This will get you the variable type.
add a comment |
$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string
$Startup.gettype() #This will get you the variable type.
add a comment |
$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string
$Startup.gettype() #This will get you the variable type.
$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string
$Startup.gettype() #This will get you the variable type.
answered Nov 16 '18 at 10:41
AameerAameer
1014
1014
add a comment |
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%2f53334207%2fconverting-object-to-a-string%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
2
Get-WmiObject Win32_StartupCommand -ComputerName | Select Caption
already returns multiple strings. You need to explain what you expect. You want to write every item to a new line? All on one line, with a delimiter?– Tomalak
Nov 16 '18 at 8:50
I just what it ti return the caption column with every item to a new line
– Adam
Nov 16 '18 at 9:00
Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". And more importantly, please read the Stack Overflow question checklist. You might also want to learn about Minimal, Complete, and Verifiable Examples.
– Clijsters
Nov 16 '18 at 9:00
2
... | Select Caption
->... | Select Caption | Out-String
?– Ansgar Wiechers
Nov 16 '18 at 9:17
Out-string has worked, thank you
– Adam
Nov 16 '18 at 9:42