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
1
vote
2 answers

Add index number to list of results of `Select-String`

I need to search for a term in a file and display an index in the search results so that referencing is easy. The command in bash would be: cat | grep 'Table: ' | cat -n What I have so far in Powershell: Get-Content | Select-String…
Khalid Hussain
  • 345
  • 4
  • 16
1
vote
1 answer

Use of Select-Object to change a property's data type and to add calculated properties

Trying to get details from object and want to save it to SQL table. $GetFiles ` | Select-Object -Property Name, Type ` | Write-SqlTableData -ServerInstance $SQLServer -DatabaseName $SQLDatabase -SchemaName $SQLSchema -TableName $SQLTable…
1
vote
2 answers

Calculated properties in pipeline expressions return null in jobs when passed using a PSObject

I am trying to pass a hashtable of calculated properties in to a query, for use with Select-Object. It works when run in the console. I can confirm that the job is reading the hashtable as it lists the selected properties in the result, yet all of…
Arbiter
  • 450
  • 5
  • 26
1
vote
2 answers

Select-Object Data Failure From Succesful Invoke-RestMethod

I have a working call to a rest service using Invoke-RestMethod -Uri https://.... The call's result, in JSON, can be piped the data to Format-Table -Property ... and data is shown. But when Select-Object -Property ... is used after the invoke with…
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
1
vote
1 answer

Get-ChildItem, List files that comply with certain parameters and then Remove-Item

I have the following script, that works fine, listing the candidate files to be remove. But I cannot figure it out where or how to add the Remove-Item instruction to actually delete the files, without losing the export file. By the way, a Write-Host…
1
vote
2 answers

Powershell - Passing command line filename to import-csv

I'm trying to add additional columns when piping output of a command to csv. the command I'm running is this: Invoke-RestMethod -Uri $uri"adminadmin
MatF
  • 13
  • 4
1
vote
2 answers

Access Script property

I am looking to run a DNS lookup for a local server, select both the hostname and IP address and output to a text file. [System.Net.Dns]::GetHostEntry('server1') | Select-Object 'HostName', 'IPAddressToString' | Out-File -Path…
1
vote
1 answer

How can I select a single property from PowerShell Expandproperty

I have a simple PowerShell expression that returns some object properties. It also returns an object called Computer which has a property called ComputerName which I'm trying to access. The ExpandProperty switch returns all the properties. How do I…
bearaman
  • 1,071
  • 6
  • 23
  • 43
1
vote
1 answer

Select-Object & empty variable

I'm trying to build an boot report for my domain computers and send it automatically by mail. though, I'm having trouble to put it into a variable to send using Send-MailMessage function. Here's the piece of code: foreach ($computer in…
1
vote
0 answers

Select-object then group-object give hashtable that I can't access by key

If I have a list of objects $o1 = New-Object –TypeName PSObject –Property @{"MyKey"= "dog"; "MyValue"="Steve"} $o2 = New-Object –TypeName PSObject –Property @{"MyKey"= "dog"; "MyValue"="Frank"} $o3 = New-Object –TypeName PSObject –Property…
1
vote
2 answers

Select attributes or parameter with variable in PowerShell

Using this code I get the desired result: Get-Service | select Name,Status But the following code will not work, do you know why? I want the user to choose his own selection of attributes. I store the attributes in a variable like shown below. But…
user5197928
1
vote
2 answers

Powershell: Export a custom object to a CSV file - extract a single property value with Select-Object

I wrote a script that constructs a custom object and exports it to a CSV file: $reg = Get-ItemProperty HKLM:\SOFTWARE\McAfee\DLP\Agent | Select-Object agentversion $date = Get-ItemProperty 'C:\Program Files\McAfee' | Select-Object…
C.Kelly
  • 23
  • 1
  • 4
1
vote
2 answers

Set a Variable from an Imported List of Servers with Select-Object

Currently I have the below script that works however I have over 30 servers and they often change so i was curious if there was a simpler way to get the $ServerList variable updated with the import data from each of my servers. The server path is…
Roger Hall
  • 35
  • 10
1
vote
2 answers

hashtable filter / select

I was working tonight to re-write an existing server health check script to store its values in a hashtable, and that part is working fine. However, I want the results to go to a CSV file, and that file only to be populated with servers where I've…
Kenny
  • 141
  • 1
  • 2
  • 13
1
vote
0 answers

Powershell select-object empty

I try to get FolderPath for Exchange Mailboxes like this: get-mailbox | select Name,@{L="FoldePath";E={(Get-MailboxFolderStatistics $_.Name).folderpath}} This gives me the following output: Name FoldePath ---- --------- User01 {/Top…
Apollo
  • 11
  • 2