Convert Selected.System.String to System.String Convert Selected.System.String to System.String powershell powershell

Convert Selected.System.String to System.String


To print your outputs as strings, try this:

'C:\x.ini','C:\y.ini' | % { [io.path]::GetExtension($_) } 

.ini

.ini

TypeName: System.String

In this case % or Foreach-Object will run the command for every input, generating the output you need. Select-Object will actually create a selection object which contains the output. There are many ways to print the contents of this object, but using Foreach-Object is likely the simplest.


If you're dealing with strings, I'd suggest just using regex:

$Paths -replace '.*?(\.\w+$)', '$1'

This will return you a [System.String[]] object with extensions in the form of .exe