Questions tagged [select-object]

PowerShell cmdlet that selects objects or object properties.

The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array.

https://technet.microsoft.com/en-us/library/hh849895.aspx

109 questions
98
votes
5 answers

How to get the captured groups from Select-String?

I'm trying to extract text from a set of files on Windows using the Powershell (version 4): PS > Select-String -AllMatches -Pattern -Path file.jsp | Format-Table So far, so good. That gives a nice set of MatchInfo…
watery
  • 5,026
  • 9
  • 52
  • 92
8
votes
2 answers

powershell select-object property AND expandproperty

Trying to execute a Select-Object, but i can't seem to return property and a value from a key-value list property. There are 3 properties i want returned RunStart, Message and 'tableName' from this Parameters property. I get too much with…
Jared Tims
  • 191
  • 1
  • 1
  • 9
8
votes
2 answers

How do I write the value of a single property of a object?

This is how my current script looks like: $cpu = Get-WmiObject win32_processor | select LoadPercentage logwrite $cpu #this fuction writes $cpu into a .txt file The output of the file is: @{LoadPercentage=4} I want it to be only the number so that…
verfluecht
  • 493
  • 6
  • 24
6
votes
4 answers

No error when selecting non-existing property

I want PowerShell to throw an error when trying to select non-existing properties, but instead I get empty column as output. Example: $ErrorActionPreference=[System.Management.Automation.ActionPreference]::Stop; Set-StrictMode -Version…
AdamL
  • 12,421
  • 5
  • 50
  • 74
4
votes
1 answer

PowerShell Select-Object: Using -Unique with First/Last/Skip/Index

I'm just curious if I'm missing any documentation, or if there is a different/better way to do this that negates the need for documentation. Maybe I'm the only one trying to use Select-Object to select the -First X unique instances from a set of…
immobile2
  • 489
  • 2
  • 15
4
votes
2 answers

select-object -expandproperty with null property

I have a collection of objects with properties like id, username, email, current_sign_in_at, identities. Where Identities property is an array of objects with two properties. This would be a json representation of an object: { "id": 45, …
mnieto
  • 3,744
  • 4
  • 21
  • 37
4
votes
3 answers

PowerShell -ExpandProperty and correct date format

I am attempting to use the -ExpandProperty feature in PowerShell to stop the header appearing in the output and format the date without minutes and seconds. This is just to get the created date for an AD Object: Get-ADComputer -Server $Server…
IanB
  • 271
  • 3
  • 13
3
votes
1 answer

Script has two variables when done, but when I pipe to SELECT-object only first one returns data to console

I am trying to query multiple servers with WMI, but I don't always have access to the servers. The code is below. Alas, it returns "access is denied" to the console, but I can't seem to get rid of it. Oh well. However, I am trapping the servers…
mbourgon
  • 1,286
  • 2
  • 17
  • 35
3
votes
1 answer

Variables not working as expected inside Select-Object expression statement

I'm attempting to add a custom column to the table output of some objects retrieved from our MECM instance. The following code shows the precise format of the code, only gathering data from Get-Process instead. $types = @{ "chrome" = "This is…
mmseng
  • 735
  • 9
  • 24
3
votes
1 answer

Select-Object -First affects prior cmdlet in the pipeline

The PowerShell Strongly Encouraged Development Guidelines that cmdlets should Implement for the Middle of a Pipeline but I suspect that isn't doable for a parameter as -Last for the Select-Object. Simply because you can't determine the last entry…
iRon
  • 20,463
  • 10
  • 53
  • 79
3
votes
1 answer

Powershell select statement

forEach($subscription in Get-AzureRmSubscription) { Select-AzureRmSubscription -SubscriptionId $subscription.Id | Out-Null Get-AzurermVM -Status | select $subscription.Name, ResourceGroupName, Name, PowerState | ConvertTo-Csv -NoTypeInformation…
Alex
  • 69
  • 1
  • 5
3
votes
0 answers

PowerShell script doesn't run synchronously

I have a function which prints the result of an Exchange cmdlet. But the output is not printed immediately. It is almost like it kind of runs asynchronous. In the following example the output is printed AFTER the first Read-Host break. I expected it…
MrCalvin
  • 1,675
  • 1
  • 19
  • 27
3
votes
1 answer

Specifiying between non default properties with Select-Object

I am practicing Powershell and the question that I have been assigned is as follows: Write a pipeline to get-process where cpu utilization is greater than zero, return properties not shown in default view and sort the results by CPU…
Justin Reid
  • 119
  • 1
  • 9
2
votes
1 answer

Powershell convert Collection? to list?

I'm trying to parse Palo Alto firewall rules with Powershell. Some rules can have ~100 servernames in them. I need to break down each name to check if they're still alive (DNS) and return rule mapping for each servername. Most of it works except…
El8Hax0r
  • 21
  • 4
2
votes
2 answers

Passing $_ item from a string collection into a function called from Select-Object

Okay... so I have a System.Data.DataRow object. I've gotten the column names out into a string collection. Then I want to get the corresponding values into a second collection. I'm sure I'm just doing something dumb here, but I cannot for the life…
eidylon
  • 7,068
  • 20
  • 75
  • 118
1
2 3 4 5 6 7 8