Truncate the values only - urgent :(

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 1 year, 11 months ago.

  • Author
    Posts
  • #21690
    Profile photo of
    Anonymous

    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> $obj.tech="N/A"

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

    Tech : N/A
    Name : PS

  • #21691
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    You can do something like this:

    foreach ($property in $Obj.PSObject.Properties) {
        $property.Value = $null
    }
    
  • #21692
    Profile photo of
    Anonymous

    wow. thats awesome. thnx Wyatt 🙂

  • #21698
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    No problem. 🙂

You must be logged in to reply to this topic.