Converting object to a string












0















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?










share|improve this question




















  • 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
















0















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?










share|improve this question




















  • 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














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












2 Answers
2






active

oldest

votes


















0















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.






share|improve this answer
























  • 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





















0














$StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string



$Startup.gettype() #This will get you the variable type.






share|improve this answer
























    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%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









    0















    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.






    share|improve this answer
























    • 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


















    0















    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.






    share|improve this answer
























    • 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
















    0












    0








    0








    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.






    share|improve this answer














    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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





















    • 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















    0














    $StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string



    $Startup.gettype() #This will get you the variable type.






    share|improve this answer




























      0














      $StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string



      $Startup.gettype() #This will get you the variable type.






      share|improve this answer


























        0












        0








        0







        $StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string



        $Startup.gettype() #This will get you the variable type.






        share|improve this answer













        $StartUp = Get-WmiObject Win32_StartupCommand | Select Caption|out-string



        $Startup.gettype() #This will get you the variable type.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 10:41









        AameerAameer

        1014




        1014






























            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%2f53334207%2fconverting-object-to-a-string%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

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values