Truncate the values only - urgent :(

This topic contains 3 replies, has 2 voices, and was last updated by  Dave Wyatt 3 years, 5 months ago.

  • Author
  • #21690


    Hi Team,
    Could you please assist me to clear the values only from a PSObject.
    PS C:\Users\SagarJyo> $props=@{Name="PS";Tech="Microsoft"}

    PS C:\Users\SagarJyo> $Obj=New-Object psobject -Property $props

    PS C:\Users\SagarJyo> $obj|fl

    Tech : Microsoft
    Name : PS
    What I want is the names Tech & Name should become empty; if its not possible or cannot be emtpy then I want replace all by a specific string. Of course I can do like below each one by one... but in my actual case I have plenty of names and cannot hotcode. I am looking for a solution. pls help me asap.

    PS C:\Users\SagarJyo> $"N/A"

    PS C:\Users\SagarJyo> $obj|fl *

    Tech : N/A
    Name : PS

  • #21691

    Dave Wyatt

    You can do something like this:

    foreach ($property in $Obj.PSObject.Properties) {
        $property.Value = $null
  • #21692


    wow. thats awesome. thnx Wyatt 🙂

  • #21698

    Dave Wyatt

    No problem. 🙂

You must be logged in to reply to this topic.