주제

 

데이터 결과 가져올때 컬럼이 있다면 제거하기

 

 

 사용법

 

Select-Object -ExpandProperty 컬럼이름

 

문제: 컬럼이름을 한개만 사용 할 수 있다.

 

스크립트에서 결과 값을 받아와서 처리할때나 결과 값을 가져올때 사용하면 될 것 같다.

 

 

 사용예

 

PS D:\test> Get-ChildItem


    디렉터리: D:\test


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----      2022-03-11   오전 7:50              0 test.txt
-a----      2022-03-11   오전 8:25              0 test2.txt


PS D:\test> Get-ChildItem | Select-Object Mode, Name

Mode   Name
----   ----
-a---- test.txt
-a---- test2.txt

문제 발생

PS D:\test> Get-ChildItem | Select-Object -ExpandProperty Mode, Name
Select-Object : 'System.Object[]'을(를) 'ExpandProperty' 매개 변수에 필요한 유형 'Syste
m.String'(으)로 변환할 수 없습니다. 지정한 메서드가 지원되지 않습니다.
위치 줄:1 문자:47
+ Get-ChildItem | Select-Object -ExpandProperty Mode, Name
+                                               ~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], ParameterBindingEx
   ception
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.Sele
   ctObjectCommand

PS D:\test> Get-ChildItem | Select-Object -ExpandProperty Name
test.txt
test2.txt
PS D:\test> Get-ChildItem | Select-Object -Expand Name
test.txt
test2.txt
PS D:\test>

 

 

 출처

 

Select-Object

 

한글로 번역해서 읽었지만 이해가 되지않아서 원문을 그대로 가져다 썼다.

영어 공부라도 할려고...

 

-ExpandProperty
Specifies a property to select, and indicates that an attempt should be made to expand that property.

If the specified property is an array, each value of the array is included in the output.
If the specified property is an object, the objects properties are expanded for every InputObject
In either case, the Type of objects output will match the Type of the expanded property.

If the Property parameter is specified, Select-Object will attempt to add each selected property as a NoteProperty to every outputted object.

 

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.2

 

 

+ Recent posts