How to get Select-Object to return a raw type (e.g. String) rather than PSCustomObject?

You just need to pick out the property you want from the objects. FullName in this case. $files = Get-ChildItem $directory -Recurse | Select-Object FullName | Where-Object {!($_.psiscontainer)} | foreach {$_.FullName} Edit: Explanation for Mark, who asks, “What does the foreach do? What is that enumerating over?” Sung Meister’s explanation is very good, but I’ll … Read more

How to initialize an array of custom objects

I’d do something along these lines: $myitems = @([pscustomobject]@{name=”Joe”;age=32;info=”something about him”}, [pscustomobject]@{name=”Sue”;age=29;info=”something about her”}, [pscustomobject]@{name=”Cat”;age=12;info=”something else”}) Note that this only works in PowerShell 3, but since you did not mention the version in your question I’m assuming this does not matter for you. Update It has been mentioned in comments that if you do the … Read more

PSCustomObject to Hashtable

Shouldn’t be too hard. Something like this should do the trick: # Create a PSCustomObject (ironically using a hashtable) $ht1 = @{ A = ‘a’; B = ‘b’; DateTime = Get-Date } $theObject = new-object psobject -Property $ht1 # Convert the PSCustomObject back to a hashtable $ht2 = @{} $theObject.psobject.properties | Foreach { $ht2[$_.Name] = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)