PowerShell에서 사용되는 GetType, 변수 간의 차이
변수 $a
와 의 차이점은 무엇입니까 $b
?
$a = (Get-Date).DayOfWeek
$b = Get-Date | Select-Object DayOfWeek
나는 확인했다
$a.GetType
$b.GetType
MemberType : Method
OverloadDefinitions : {type GetType()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : type GetType()
Name : GetType
IsInstance : True
MemberType : Method
OverloadDefinitions : {type GetType()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : type GetType()
Name : GetType
IsInstance : True
그러나 이러한 변수의 출력이 다르게 보이지만 차이가없는 것 같습니다.
우선 GetType을 호출 할 괄호가 없습니다. 보이는 것은 [DayOfWeek]의 GetType 메서드를 설명하는 MethodInfo입니다. 실제로 GetType을 호출하려면 다음을 수행해야합니다.
$a.GetType();
$b.GetType();
당신은 그 표시됩니다 $a
A [된 요일], 그리고 $b
에 의해 생성 된 사용자 정의 개체입니다 선택 - 개체 캡처 cmdlet을 데이터 개체 만 된 요일 속성을. 따라서 DayOfWeek 속성 만있는 개체입니다.
C:\> $b.DayOfWeek -eq $a
True
Select-Object는 새 psobject를 만들고 요청한 속성을 복사합니다. GetType ()으로이를 확인할 수 있습니다.
PS > $a.GetType().fullname
System.DayOfWeek
PS > $b.GetType().fullname
System.Management.Automation.PSCustomObject
Select-Object 는 지정된 속성 만 있는 사용자 지정 PSObject 를 반환 합니다. 단일 속성이 있어도 ACTUAL 변수를 얻지 못합니다. PSObject 내부에 래핑됩니다.
대신 다음을 수행하십시오.
Get-Date | Select-Object -ExpandProperty DayOfWeek
다음과 같은 결과를 얻을 수 있습니다.
(Get-Date).DayOfWeek
차이점은 Get-Date 가 여러 개체를 반환 하는 경우 파이프 라인 방식이 괄호 방식보다 더 잘 작동한다는 것 (Get-ChildItem)
입니다. 예를 들어는 항목의 배열입니다. 이는 PowerShell v3에서 변경되었으며 (Get-ChildItem).FullPath
예상대로 작동하며 전체 경로의 배열 만 반환합니다.
참고 URL : https://stackoverflow.com/questions/7634555/gettype-used-in-powershell-difference-between-variables
'developer tip' 카테고리의 다른 글
Android에서 개발하는 데 사용할 수있는 프로그래밍 언어는 무엇입니까? (0) | 2020.11.04 |
---|---|
3면 테두리 (0) | 2020.11.04 |
Sass-단일 태그의 두 클래스 (0) | 2020.11.04 |
Dart 언어의 Console.log (0) | 2020.11.04 |
자바 스크립트를 사용한 부동 합계 (0) | 2020.11.04 |