2014. 9. 26. 15:44

  • 날짜 및 시간을 확인하는 cmdlet는 Get-Date이다. Get-Date에서 다양한 Property를 이용하여 정보를 추출할 수 있다. 아래의 예를 한 번 살펴보자.
    • Get-Date
    • Get-Date | Format-List *
    • Get-Date | Get-Member
    • (Get-Date).AddDays(-1) –이것은 오늘 기준으로 하루 전의 Get-Date를 확인한다
      (Get-Date).AddDays(-2)
      (Get-Date).AddDays(10) — 오늘 기준으로 10일 후의 Get-Date 정보 확인
    • (Get-Date).ToString(‘yyyy-MM-dd’) –간단하게 오늘 날짜를 표현하기
      (get-date).AddDays(-1).ToString(‘yyyy-MM-dd’)


       
       

  • 2일전부터 오늘까지만 발생한 이벤트 정보 중에서 Error만을 확인해보자.        
    • Get-EventLog -LogName Application -EntryType Error -After (Get-Date).AddDays(-2)
    • Get-EventLog -LogName System -EntryType Error -After (Get-Date).AddDays(-2)
  • 이렇게 하면 특정한 날짜 기간에만 오류를 발생한 정보를 확인할 수 있다. 특히 (Get-Date).AddDays(-2) 형식을 잘 알아두어야 한다.
출처 : http://cloudsns.wordpress.com/category/microsoft/powershell/page/7/

Posted by pegasuss
2014. 9. 26. 11:12

  • NIC의 정보를 쉽게 확인하는 방법은 다음과 같다.
    Get-WmiObject -Class Win32_*network* -List


  • 여기서 IP 구성 정보를 확인하는 Win32_NetworkAdapterConfiguration을 이용하면 편리하다
    Get-WmiObject -Class Win32_NetworkAdapterConfiguration
    Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Format-List *

    (여기서 IPEnabled가 True인 것을 참고한다.)
    Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.IPEnabled -eq ‘True’}
    (이렇게 하면 로컬 컴퓨터 IP 구성 상황을 모두 알 수 있다.)


    Get-WmiObject -Class Win32_NetworkAdapterConfiguration -ComputerName Server1 | Where {$_.IPEnabled -eq ‘True’}
    (이렇게 하면 원격 컴퓨터 IP 구성 상황을 모두 알 수 있다.)
     

  • 네트워크 어댑터 종류들을 확인해보자.
    Get-WmiObject -Class Win32_NetworkAdapter
    Get-WmiObject -Class Win32_NetworkAdapter | FT name



    Get-WmiObject -Class Win32_NetworkAdapter
    -ComputerName Server1 | FT name


    출처 : http://cloudsns.wordpress.com/category/microsoft/powershell/page/7/

Posted by pegasuss
2014. 9. 26. 10:50

  • 컬 컴퓨터 및 원격 컴퓨터의 디스크와 관련된 정보를 확인하기 위해서는 Get-WmiObject를 이용하면 된다.
  • 먼저 disk와 관련된 Get-WmiObject를 확인하기 위해서 다음과 같이 하면 사용 가능한 목록을 확인할 수 있다.
    Get-WmiObject -Class Win32_*Disk* -List 


  • 이제 각각의 정보를 한 번 살펴보자.
    Get-WmiObject -Class Win32_LogicalDisk
    Get-WmiObject -Class Win32_LogicalDisk -ComputerName Server1
    (원격지에 위치한 컴퓨터의 디스크 정보도 알 수 있다.)

    Get-WmiObject -Class Win32_MappedLogicalDisk
    Get-WmiObject -Class Win32_MappedLogicalDisk -ComputerName Server1
    (원격 컴퓨터가 어느 fileserver에 연결되어 있는지 알 수 있다.)
    Get-WmiObject -Class Win32_MappedLogicalDisk -ComputerName Server1 | ft name, providername, freespace -autosize
    (이렇게 하면 원격 컴퓨터 Server1이 어느 File server에 어떤 드라이브로 연결되어 있는지 간략하게 알 수 있다.)

    Get-WmiObject -Class Win32_DiskPartition
    Get-WmiObject -Class Win32_DiskPartition -ComputerName Server1

    Get-WmiObject -Class Win32_DiskDrive
    Get-WmiObject -Class Win32_DiskPartition -ComputerName Server1

    Get-WmiObject -Class Win32_DiskQuota
    Get-WmiObject -Class Win32_DiskQuota -ComputerName Server1
    (각 사용자 단위로 디스크 할당량 정도를 확인할 수 있다. 원격 컴퓨터도 마찬가지.)


    출처 : http://cloudsns.wordpress.com/category/microsoft/powershell/page/8/

Posted by pegasuss
2014. 9. 26. 10:32

  • 로컬 컴퓨터의 Disk Controller에 문제가 있는지 확인하여 본다.
    • Get-EventLog -LogName System -InstanceId 3221487627 -ErrorAction 0
    • Get-EventLog -LogName System -InstanceId 3221487627 -ErrorAction 0 | ForEach-Object {$_.ReplacementStrings[0] } | Group-Object -NoElement | Sort-Object Count -Descending


  • 이렇게 하여 나온 것 중에 대부분은 USB drive를 강제로 빼서 생기는 것이 많다.
출처 : http://cloudsns.wordpress.com/category/microsoft/powershell/page/8/

Posted by pegasuss
2014. 9. 24. 17:49

  • 다음과 같이 실행하면 로컬 컴퓨터에서 사용한 USB 스토리지 정보를 Registry에 추출하여 확인할 수 있다.

    $key = ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\*’
    Get-ItemProperty $key | Select-Object -ExpandProperty FriendlyName | Sort-Object 

  • 이것을 한 줄로 해결할 수 있다.(semicolon 사용)
    $key = ‘Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\*’;
    Get-ItemProperty $key | Select-Object -ExpandProperty FriendlyName | Sort-Object 

  • 이것을 스크립트로 만들어 사용하여 원격 컴퓨터에서 사용한 USB 종류를 알 수도 있다. 즉, PickupUSBtype.ps1 파일로 만들어서 다음과 같이 하면 원격 컴퓨터에서 사용한 USB 종류들을 확인할 수 있다.
    Invoke-Command -FilePath c:\myscripts\PickupUSBtype.ps1 -ComputerName pc1, pc2, pc3
출처 : http://cloudsns.wordpress.com/category/microsoft/powershell/page/8/

Posted by pegasuss