• exception 이름 알아내기
    $error[0].exception.getType().fullname
    


  • catch 문
    try {
    	...
    } catch {
    	Write-Warning $_
    }
    


  • eventlog 얻기
    get-eventlog system -source *Hyper-V* -EntryType error, warning `
    					  -after "2020/07/20" -before "2020/08/04" | out-gridview
    


  • get-computerinfo 안 먹힐 때
    winrm quickconfig -quiet
    


  • stdout null로 redirect
    | Out-Null  
    


  • Import module
    Import-module "module1.psm1" 
    Import-module ".\common.ps1"
    . ".\common.ps1"
    


    • module에 parameter 전달
      Import-module "module1.psm1" -ArgumentList $args[0], $args[1]
      Import-module "module1.psm1" -Dev:$true # switchparameter(있으면 true, 없으면 false인 parameter)
      


  • approved verbs (승인된 동사)
    • 함수명 작성 시 prefix로 승인된 동사가 정해져 있다.
    • https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7
    • powershell에 get-verbs를 입력하면 나온다.

  • 사전 hwinfo 조사
    get-ciminstance -class "cim_physicalmemory" | % { $physicalMemSize += [long]$_.Capacity }
    $physicalMemSize /= 1GB
    	# OR
    $currentPhysicalMemSize = (Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum / 1GB
      
    Set-VMMemory $VM_NAME -StartupBytes $startupMemorySize  # 수정 필요 (동적 할당 여부, 기본 메모리 사이즈)
    Set-VmProcessor $VM_NAME -Count $startupProcessorCount # 수정 필요 (processor core 개수, )
      
      
    Get-CimInstance -Class CIM_Processor -ErrorAction Stop | Select-Object * | Select -ExpandProperty Name
    #'Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz' 에서 '8700' 중 8이 세대(generation)를 의미
    #'AMD Ryzen 7 1700X' 에서 '7'은 성능, '1700' 중 1이 세대(generation)를 의미
    Get-CimInstance -Class CIM_Processor -ErrorAction Stop | Select-Object * | Select -ExpandProperty NumberOfCores
    Get-CimInstance -Class CIM_Processor -ErrorAction Stop | Select-Object * | Select -ExpandProperty NumberOfLogicalProcessors
    


  • powershell script 실행 에러(권한 문제)
    powershell.exe -ExecutionPolicy Bypass -File .\example.ps1