Author Posts

January 6, 2015 at 9:45 am

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

January 6, 2015 at 9:47 am

You can do something like this:

foreach ($property in $Obj.PSObject.Properties) {
    $property.Value = $null
}

January 6, 2015 at 9:52 am

wow. thats awesome. thnx Wyatt 🙂

January 6, 2015 at 10:06 am

No problem. 🙂