# specify the date you want to examine # default is today $date = Get-Date $year = $date.Year $month = $date.Month
# create a new DateTime object set to the first day of a given month and year $startOfMonth = Get-Date-Year$year-Month$month-Day1-Hour0-Minute0-Second0-Millisecond0 # add a month and subtract the smallest possible time unit $endOfMonth = ($startOfMonth).AddMonths(1).AddTicks(-1)
大多数 IP 地址可以用 Web Service 定位到物理地址。以下是一个很简单的函数,能够输入一个 IP 地址并返回它的物理地址:
1 2 3 4 5 6 7
#requires -Version 3.0
functionGet-IPLocation([Parameter(Mandatory)]$IPAddress) { Invoke-RestMethod-Method Get -Uri"http://geoip.nekudo.com/api/$IPAddress" | Select-Object-ExpandProperty Country -Property City, IP, Location }
name : United States code : US city : Mountain View ip : 8.8.8.8 location : @{accuracy_radius=1000; latitude=37,386; longitude=-122,0838; time_zone=America/Los_Angeles}
And here is how you can resolve any hostname to an IP address, for example, the famous powershellmagazine.com: 以下是如何将任意主机名解析成 IP 地址的代码,例如知名的 powershellmagazine.com:
name : United States code : US city : New York ip : 104.131.21.239 location : @{accuracy_radius=1000; latitude=40,7143; longitude=-74,006; time_zone=America/New_York}
(of course this is just where the server sits, not Aleksandar or Ravi or all the other fine editors (当然这只代表了服务器的所在地,而不是 Aleksandar or Ravi 及其它知名编辑的位置 )