Extract string without spacing in powershell cmdletWhat is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Determine installed PowerShell versionDoes Python have a string 'contains' substring method?Why is char[] preferred over String for passwords?

Can criminal fraud exist without damages?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

How will losing mobility of one hand affect my career as a programmer?

Efficiently merge handle parallel feature branches in SFDX

How do I define a right arrow with bar in LaTeX?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

How do I rename a LINUX host without needing to reboot for the rename to take effect?

How do I keep an essay about "feeling flat" from feeling flat?

voltage of sounds of mp3files

Applicability of Single Responsibility Principle

Personal Teleportation as a Weapon

What't the meaning of this extra silence?

Valid Badminton Score?

Why is `const int& k = i; ++i; ` possible?

is this a spam?

Was Spock the First Vulcan in Starfleet?

Is there any easy technique written in Bhagavad GITA to control lust?

What does this 7 mean above the f flat

Is there a good way to store credentials outside of a password manager?

Is there any reason not to eat food that's been dropped on the surface of the moon?

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

What is difference between behavior and behaviour

Lay out the Carpet

Ways to speed up user implemented RK4



Extract string without spacing in powershell cmdlet


What is the difference between String and string in C#?How do I iterate over the words of a string?How do I read / convert an InputStream into a String in Java?Case insensitive 'Contains(string)'How do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Determine installed PowerShell versionDoes Python have a string 'contains' substring method?Why is char[] preferred over String for passwords?













0















I have some powershell script . Instead totalcmd* you can type another process you want.



$tc = get-process -Name totalcmd* | format-wide -property Name 
echo $tc
if ($tc -eq "Totalcmd64")

Stop-Process -Name totalcmd*

Start-Sleep 10


It doesn't work, I think, because, my $tc not equal to string "totalcmd". How can I remove unwanted spaces of cmdlet get-process -Name totalcmd* | format-wide -property Name output and compare strings correctly?










share|improve this question



















  • 1





    If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

    – Joseph
    Mar 8 at 12:06















0















I have some powershell script . Instead totalcmd* you can type another process you want.



$tc = get-process -Name totalcmd* | format-wide -property Name 
echo $tc
if ($tc -eq "Totalcmd64")

Stop-Process -Name totalcmd*

Start-Sleep 10


It doesn't work, I think, because, my $tc not equal to string "totalcmd". How can I remove unwanted spaces of cmdlet get-process -Name totalcmd* | format-wide -property Name output and compare strings correctly?










share|improve this question



















  • 1





    If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

    – Joseph
    Mar 8 at 12:06













0












0








0








I have some powershell script . Instead totalcmd* you can type another process you want.



$tc = get-process -Name totalcmd* | format-wide -property Name 
echo $tc
if ($tc -eq "Totalcmd64")

Stop-Process -Name totalcmd*

Start-Sleep 10


It doesn't work, I think, because, my $tc not equal to string "totalcmd". How can I remove unwanted spaces of cmdlet get-process -Name totalcmd* | format-wide -property Name output and compare strings correctly?










share|improve this question
















I have some powershell script . Instead totalcmd* you can type another process you want.



$tc = get-process -Name totalcmd* | format-wide -property Name 
echo $tc
if ($tc -eq "Totalcmd64")

Stop-Process -Name totalcmd*

Start-Sleep 10


It doesn't work, I think, because, my $tc not equal to string "totalcmd". How can I remove unwanted spaces of cmdlet get-process -Name totalcmd* | format-wide -property Name output and compare strings correctly?







string powershell comparison






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 12:18









LotPings

19.9k61633




19.9k61633










asked Mar 8 at 10:07









SergioSergio

164111




164111







  • 1





    If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

    – Joseph
    Mar 8 at 12:06












  • 1





    If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

    – Joseph
    Mar 8 at 12:06







1




1





If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

– Joseph
Mar 8 at 12:06





If you end up with more than one process that starts with "totalcmd", then your "if" statement will never evaluate to true because the array object $tc will never equal a string object "Totalcmd64".

– Joseph
Mar 8 at 12:06












3 Answers
3






active

oldest

votes


















1














You do not end up with a string because you pipe to format-wide. These cmdlets are best for representing data on the screen. Instead select the property and use -ExpandProperty to return it as a string:



$tc = get-process -Name totalcmd* | Select-Object -ExpandProperty Name 
echo $tc
...





share|improve this answer






























    1














    You are generally correct that $tc is not equal to "totalcmd" and that is because when you set $tc, you are creating an array (most likely of one element). You can test that by running $tc | get-member to see what kind of object you are working with.



    To work with string objects, you could use the Out-String cmdlet as well.






    share|improve this answer






























      1














      If you want to explicitly stop TotalCmd64 processes why not simply use:



      Get-Process -Name TotalCmd64 | Stop-Process


      If you want to switch between 64/32bit versions of the program, use a switch statement (untested):



      $tc = (Get-Process -Name TotalCmd*).Name
      switch ($tc)
      'TotalCmd' Get-Process -Name TotalCmd
      'TotalCmd64' Stop-Process;"Start TotalCmd32";Break
      default "No TotalCmd* processes found"






      share|improve this answer

























      • May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

        – Sergio
        Mar 8 at 12:22











      • See extended answer to switch between 64/32bit versions.

        – LotPings
        Mar 8 at 12:43










      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%2f55060907%2fextract-string-without-spacing-in-powershell-cmdlet%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You do not end up with a string because you pipe to format-wide. These cmdlets are best for representing data on the screen. Instead select the property and use -ExpandProperty to return it as a string:



      $tc = get-process -Name totalcmd* | Select-Object -ExpandProperty Name 
      echo $tc
      ...





      share|improve this answer



























        1














        You do not end up with a string because you pipe to format-wide. These cmdlets are best for representing data on the screen. Instead select the property and use -ExpandProperty to return it as a string:



        $tc = get-process -Name totalcmd* | Select-Object -ExpandProperty Name 
        echo $tc
        ...





        share|improve this answer

























          1












          1








          1







          You do not end up with a string because you pipe to format-wide. These cmdlets are best for representing data on the screen. Instead select the property and use -ExpandProperty to return it as a string:



          $tc = get-process -Name totalcmd* | Select-Object -ExpandProperty Name 
          echo $tc
          ...





          share|improve this answer













          You do not end up with a string because you pipe to format-wide. These cmdlets are best for representing data on the screen. Instead select the property and use -ExpandProperty to return it as a string:



          $tc = get-process -Name totalcmd* | Select-Object -ExpandProperty Name 
          echo $tc
          ...






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 10:12









          arco444arco444

          16.4k74152




          16.4k74152























              1














              You are generally correct that $tc is not equal to "totalcmd" and that is because when you set $tc, you are creating an array (most likely of one element). You can test that by running $tc | get-member to see what kind of object you are working with.



              To work with string objects, you could use the Out-String cmdlet as well.






              share|improve this answer



























                1














                You are generally correct that $tc is not equal to "totalcmd" and that is because when you set $tc, you are creating an array (most likely of one element). You can test that by running $tc | get-member to see what kind of object you are working with.



                To work with string objects, you could use the Out-String cmdlet as well.






                share|improve this answer

























                  1












                  1








                  1







                  You are generally correct that $tc is not equal to "totalcmd" and that is because when you set $tc, you are creating an array (most likely of one element). You can test that by running $tc | get-member to see what kind of object you are working with.



                  To work with string objects, you could use the Out-String cmdlet as well.






                  share|improve this answer













                  You are generally correct that $tc is not equal to "totalcmd" and that is because when you set $tc, you are creating an array (most likely of one element). You can test that by running $tc | get-member to see what kind of object you are working with.



                  To work with string objects, you could use the Out-String cmdlet as well.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 8 at 10:14









                  JosephJoseph

                  389719




                  389719





















                      1














                      If you want to explicitly stop TotalCmd64 processes why not simply use:



                      Get-Process -Name TotalCmd64 | Stop-Process


                      If you want to switch between 64/32bit versions of the program, use a switch statement (untested):



                      $tc = (Get-Process -Name TotalCmd*).Name
                      switch ($tc)
                      'TotalCmd' Get-Process -Name TotalCmd
                      'TotalCmd64' Stop-Process;"Start TotalCmd32";Break
                      default "No TotalCmd* processes found"






                      share|improve this answer

























                      • May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                        – Sergio
                        Mar 8 at 12:22











                      • See extended answer to switch between 64/32bit versions.

                        – LotPings
                        Mar 8 at 12:43















                      1














                      If you want to explicitly stop TotalCmd64 processes why not simply use:



                      Get-Process -Name TotalCmd64 | Stop-Process


                      If you want to switch between 64/32bit versions of the program, use a switch statement (untested):



                      $tc = (Get-Process -Name TotalCmd*).Name
                      switch ($tc)
                      'TotalCmd' Get-Process -Name TotalCmd
                      'TotalCmd64' Stop-Process;"Start TotalCmd32";Break
                      default "No TotalCmd* processes found"






                      share|improve this answer

























                      • May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                        – Sergio
                        Mar 8 at 12:22











                      • See extended answer to switch between 64/32bit versions.

                        – LotPings
                        Mar 8 at 12:43













                      1












                      1








                      1







                      If you want to explicitly stop TotalCmd64 processes why not simply use:



                      Get-Process -Name TotalCmd64 | Stop-Process


                      If you want to switch between 64/32bit versions of the program, use a switch statement (untested):



                      $tc = (Get-Process -Name TotalCmd*).Name
                      switch ($tc)
                      'TotalCmd' Get-Process -Name TotalCmd
                      'TotalCmd64' Stop-Process;"Start TotalCmd32";Break
                      default "No TotalCmd* processes found"






                      share|improve this answer















                      If you want to explicitly stop TotalCmd64 processes why not simply use:



                      Get-Process -Name TotalCmd64 | Stop-Process


                      If you want to switch between 64/32bit versions of the program, use a switch statement (untested):



                      $tc = (Get-Process -Name TotalCmd*).Name
                      switch ($tc)
                      'TotalCmd' Get-Process -Name TotalCmd
                      'TotalCmd64' Stop-Process;"Start TotalCmd32";Break
                      default "No TotalCmd* processes found"







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 8 at 12:43

























                      answered Mar 8 at 12:16









                      LotPingsLotPings

                      19.9k61633




                      19.9k61633












                      • May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                        – Sergio
                        Mar 8 at 12:22











                      • See extended answer to switch between 64/32bit versions.

                        – LotPings
                        Mar 8 at 12:43

















                      • May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                        – Sergio
                        Mar 8 at 12:22











                      • See extended answer to switch between 64/32bit versions.

                        – LotPings
                        Mar 8 at 12:43
















                      May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                      – Sergio
                      Mar 8 at 12:22





                      May be you right. Globally, I need script for restart Totalcmd64.exe to Totalcmd.exe and vice versa.

                      – Sergio
                      Mar 8 at 12:22













                      See extended answer to switch between 64/32bit versions.

                      – LotPings
                      Mar 8 at 12:43





                      See extended answer to switch between 64/32bit versions.

                      – LotPings
                      Mar 8 at 12:43

















                      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%2f55060907%2fextract-string-without-spacing-in-powershell-cmdlet%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

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived