psobject

Powershell: Piping output of pracl command to array

本小妞迷上赌 提交于 2021-02-08 09:29:25
问题 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 to do that by using the following code $inputfile = "share.txt" $outputFile = "out.csv" foreach( $path in Get-Content $inputfile) { $results=.\pracl.exe $path { foreach ($result in $results) {write-host $path,$line} } $objResult = [pscustomobject]

Access PSObject property by name in C#

一世执手 提交于 2020-12-02 06:00:49
问题 For example I have a PSObject transaction with two properties: id and transactionName , so that it looks like: transaction { id: 123 transactionName : tranName1 } and I want to return the id of the transaction if its name is tranName1. It looks to me that in powershell scripts, we can simply do: if $transaction.transactionName -eq tranName return $transaction.id however in c# it will give error since it cannot recognize the property by name... any ideas how to do it in c#? 回答1: Try something

Unexpected results when reusing a custom object for the pipeline

丶灬走出姿态 提交于 2020-02-04 17:00:30
问题 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 this in the pipeline. As the Join-Object cmdlet is rather complex, I have created a simplified cmdlet to show the specific issue: (The PowerShell version is: 5.1.16299.248 ) Function Test($Count) { $PSObject = New-Object PSObject -Property @{Name =

Unexpected results when reusing a custom object for the pipeline

天大地大妈咪最大 提交于 2020-02-04 17:00:16
问题 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 this in the pipeline. As the Join-Object cmdlet is rather complex, I have created a simplified cmdlet to show the specific issue: (The PowerShell version is: 5.1.16299.248 ) Function Test($Count) { $PSObject = New-Object PSObject -Property @{Name =

Is it possible to attach an event to a PSObject?

五迷三道 提交于 2019-12-20 03:17:07
问题 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 $o Is it possible to attach an event so that the method Sqrt() is executed when the value attribute change ? ie : PS>$o.value=9 will produce the square root of 9 is 3 update As per @Richard answer this is the working recipe : $o=New-Object PSObject

Export-csv formatting. Powershell

做~自己de王妃 提交于 2019-12-11 14:13:14
问题 Let's start off by saying that I'm quite new to Powershell and not the greatest one working with it's code and scripts but trying to learn. And now to the problem! I'm working on a script that fetches information from computers in the network. I've got some code that works quite well for my purposes. But I'm having some problem when it comes to some information, mostly information that contains multiple objects, like service. #This application will pull information from a list of devices. The

Powershell - how edit existing property in custom object

天涯浪子 提交于 2019-12-09 04:26:28
I looking for way how update noteproperty in existing psobject, for example I have system.array of psobjects ($a): Group Assigment ----- --------- Group1 Home Group2 Office Question is how update 'Home' to something other. $a | gm: TypeName: System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() Assigment NoteProperty System.String Assigment=Office Group NoteProperty System.String Group=Group1 $a.GetType():

PowerShell: Custom Property XML Tags with ConvertTo-XML Output

允我心安 提交于 2019-12-08 16:13:50
问题 I am creating a new object in PowerShell, using a hash table to set property values. I want to then export the object into XML format using the ConvertTo-XML method. $hash = @{ Processor = 'Intel' Disk = '500GB' Server = 'ABC' Serial = '01234' } $specs = New-Object PSObject -Property $hash Write-Output ($specs | ConvertTo-XML -notypeinformation).Save("C:\scripts\export.xml") The XML output is as follows: <Objects> <Object> <Property Name="Serial">a1b2c3</Property> <Property Name="Server">ABC<