Questions tagged [psobject]

PSObject is used for object encapsulation in PowerShell and is used for a consistent view in its environment.

174 questions
2
votes
4 answers

Powershell Pipeline - return a new Object, that was created within pipline

I keep running into the same problem again, and i have my default way of handling it, but it keeps bugging me. Isn't there any better way? So basicly i have a pipline running, do stuff within the pipline, and want to return a Key/Value Pair from…
Evilcat
  • 388
  • 3
  • 9
2
votes
4 answers

Powershell: How to properly count number of items in array of objects when there is only one object left in array

I have an array of objects with N properties each. I perform a subset operation using Where-Object like this, for instance: $mySubset = $myArrayOfObjects | Where-Object {($_.Property1 -eq 'ABC') -and ($_.Property2 -eq 'DEF')} I then need to check…
miguello
  • 544
  • 5
  • 15
2
votes
2 answers

Call Python script per PowerShell & passing PSObject and return the parsed data

some background: currently I am querying 4Mio rows (with 50 columns) from a MS SQL server with dbatools into a PSObject (in Batch 10.000 rows each query), processing the data with PowerShell (a lot of RegEx stuff) and writing back into a MariaDb…
TefoD
  • 177
  • 10
2
votes
1 answer

Powershell: Piping output of pracl command to array

pracl is a sysinternal command that can be used to list the ACLs of a directory. I have a list of shares and I want to create a csv file such that for each ACL entry, I want the share path in one column and share permission in the next. I was trying…
Raju Ks
  • 41
  • 3
2
votes
1 answer

Issues Overloading ToString on Nested PSObject Property

I've created a custom PSObject with a variety of properties and I'm trying to overload ToString for a few of them. I've had success with the one of the TimeSpan properties, but not with one that is a WMI object. # Get WMI info $wmiOS = Get-WmiObject…
2
votes
1 answer

Unexpected results when reusing a custom object for the pipeline

A while ago I changed my Join-Object cmdlet which appeared to cause a bug which didn’t reveal in any of my testing. The objective of the change was mainly code minimizing and trying to improve performance by preparing a custom PSObject and reusing…
iRon
  • 20,463
  • 10
  • 53
  • 79
2
votes
0 answers

How to clone a PowerShell PSCustomObject variable to disconnect it from another variable?

I'm looking for a better solution to the following problem. This code: $a = "{value:'1'}" | ConvertFrom-Json $b = $null Write-Output ("a: {0} - b: {1}" -f $a, $b) $b = $a Write-Output ("a: {0} - b: {1}" -f $a, $b) $a.value = '2' Write-Output ("a:…
Frank van Eykelen
  • 1,926
  • 1
  • 23
  • 31
2
votes
2 answers

Change a specific value in a PSObject

So I have an item's name defined as $name, and a table/object of items called $x. That looks like Name id PendingShutdown ____ ___ ___________ example j-12453634 False my variable $name = "example" What I want to do is…
Montel Edwards
  • 400
  • 5
  • 14
2
votes
2 answers

Powershell - Get Last 3 char from AD attribute in PsObject

I got a script which export to csv some AD attributes I want to have the last 3 characters of the 'initials' attribute in a PsObject but i have an error and i spent Hours on this... Could you help me ? The Error: *Method invocation failed because…
olivier
  • 45
  • 2
  • 8
2
votes
1 answer

Running powershell with C#

I am trying to run the following powershell command inside of C# Powershell: "Get-ADDomainController -Filter * | Select-Object Name,OperatingSystem,OperatingSystemServicePack,Site | Format-List" Here is my C# Code: using (PowerShell inst =…
Paul Coan
  • 302
  • 1
  • 3
  • 15
2
votes
3 answers

netsh result to a PowerShell object

I am trying to work with NETSH from PowerShell. I want see a result from this command such as an object, but netsh returns a string: netsh wlan show hostednetwork | Get-Member TypeName: System.String ... My script must work on system with rather…
kostaNew
  • 41
  • 1
  • 3
2
votes
1 answer

Tostring() method of custom powershell objects and export-clixml

1. I have these XML-files which contain data from 3rd-Party cmdlets exported via export-clixml as a backup.    They look like this (only with more objects):
Rob
  • 472
  • 4
  • 17
2
votes
2 answers

Convert PowerShell object to string

I am pulling data from a web service and want to convert the object data into a string. I am calling using: $URI = "http://siteURL" $Con = New-WebServiceProxy -uri $URI -namespace WebServiceProxy -class Nlyte $WebCon= $con.GetData('Server') $OpenCon…
Samuel Meddows
  • 36,162
  • 12
  • 38
  • 36
2
votes
1 answer

Is it possible to attach an event to a PSObject?

Say I've a psobject like this : $o=New-Object PSObject -Property @{"value"=0} Add-Member -MemberType ScriptMethod -Name "Sqrt" -Value { echo "the square root of $($this.value) is $([Math]::Round([Math]::Sqrt($this.value),2))" } -inputObject…
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
2
votes
2 answers

How can you use GetType().GetProperties() on a PowerShell Custom PSObject?

I am trying to get this log4net customization to work with PowerShell PSObjects. Basically, this pattern layout will iterate over the object and dump its properties into CSV columns. Here is the code that does the reflection: PropertyInfo[]…
Andy Schneider
  • 8,516
  • 6
  • 36
  • 52
1 2
3
11 12