2016年11月10日木曜日

◆自分が所属するグループをリストする

Getting List of Current Group Memberships - Power Tips - PowerTips - IDERA Community

#requires -Version 3.0
[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups.Value

上記で自分が所属するグループのSIDが表示される
image_thumb[1] 

名称変換も加えたのが以下

#requires -Version 3.0
[System.Security.Principal.WindowsIdentity]::GetCurrent().Groups.Translate( [System.Security.Principal.NTAccount])

image

ActiveDirectoryのモジュールは不要。
「CONSOLE LOGON」のような動的?なグループも含めてすべて表示されるようだ。

2016年11月7日月曜日

◆IPアドレスのロケーションを表示

http://community.idera.com/powershell/powertips/b/tips/posts/finding-location-of-ip-address

 

001
002
003
004
005
006
007
008
009
010

#requires -Version 3.0

function Get-IPLocation([Parameter(Mandatory)]$IPAddress
)
{

    $geoip = "http://geoip.nekudo.com/api/$IPAddress"
    Invoke-RestMethod -Method Get -Uri $geoip |
      Select-Object -ExpandProperty Country -Property City, IP, Location
 
}


Get-IPLocation -IPAddress 8.8.8.8

image

Restが簡単に使えますってサンプルかな。
個人的には、ロケーションを調べることは無いと思うがこのメソッドは覚えておきたい。

あと、以前はExpandPropertyとPropertyは共存できなかったと記憶しているが、できるようになってるんですね。

3.0から?

◆DHCPで設定されたアドレスを取得する

>Get-NetIPAddress | ? PrefixOrigin –eq DHCP | % IPAddress