기본 구조
명령어 구조(#Command Structure)
- Verb-Noun(동사-명사) -Parameter <arg1> -Parameter <arg2, arg3>
- Parameter는 명령어(cmdlet)가 어떤 작업을 수행할지 옵션이고, 항상(-) 가로줄 치고 적어야 한다.
-예시) Get-EventLog -Logname Application -InstanceId 0.1
#인수(파라미터) 셋1번(Parameter Set#1)
Get-EventLog [-Logname] <String> [[-InstanceId] <Int64>] [-After <DateTime>] [-AsBaseObject] [-Before <DateTime>]
[-ComputerName <String[]>] [-EntryType {Error | Information | FailureAudit | SuccessAudit | Warning}] 등등
#인수(파라미터) 셋2번(Parameter Set#2)
Get-EventLog [-AsString] [-ComputerName <String[]> [-List]
!!! -> 절대로 셋1번과 셋2번 섞어서 쓰면 안된다. 셋1번 쓰면 1번에서만 있는 것으로 써야 한다.
#인수(파라미터) 셋1번(Parameter Set#1)
Get-Service [-ComputerName <String[]>] [-DependentServices] -DisplayName <String[]>
=> cmdlet에서 인수가 [] 괄호 안에 들어가 있으면 옵션이다. 즉 넣어도 되고 않넣어도 된다는 뜻이다. 그러나 만약 <arg>가 대괄호 안에 들어가 있지 않으면 넣어야 한다. Get-EventLog [-LogName] <String>인 경우에는 [-LogName] 파라미터는 옵션이지만 <String> argument는 대괄호가 없기 때문에 반드시 넣어야 한다. 않넣으면 파워쉘에서 넣으라고 한다.
*Get-Help -ShowWindow에 들어가면 매개변수(parameter)에 위치(position)이 있는데 이게 어느 순서가 먼저 나오는지 말해준다. 만약 위치가 named인 경우에는 어느 위치에 들어가도 상관 없다.
*Get-EventLog [-Logname] <String> -EntryType{Error| Information | FailureAudit | SuccessAudit | Warning}
=> Curly brackets {} 안에 들어가 있고 | 는 or문이라고 생각하면 된다. 하나씩 골라도 된다는 뜻이다.
[-
EntryType {Error | Information | FailureAudit | SuccessAudit | Warning}][-
EntryType {Error | Information | FailureAudit | SuccessAudit | Warning}]