Powershell works with cmdlets. Among cmdlets there are analogues of commands from the command line (CMD).
He command line cmd is markedly different as follows:
- It is possible to transfer the results of running one cmdlet to others, filter and sort the results.
- It is possible to call .Net Framework static functions.
About other differences google, if required.
Let us analyze your example script in rows (first part)
$hostname = "microsoft.com" $result = [System.Net.Dns]::GetHostByName($hostname) $result.AddressList | ForEach-Object {$_.IPAddressToString}
- Variable declaration
- Variable declaration (type
IPHostEntry ). The function call .Net Framework System.Net.Dns.GetHostByName (string hostName) . This function returns the result of type System.Net.IPHostEntry - We take from the result the value of AddressList . In fact, this is not a single value, but a list of System.Net.IPAddress values. Next, run the cmdlet, which iterates the list of these System.Net.IPAddress, converts each of them into a string and displays it in the console.
The second part of the script
# или воспользоваться циклом если нужно проверить несколько хостов: # Массив доменных имен для проверки $name = 'remotehelp.pp.ua','remoteadministrator.pp.ua' # Сервер имен который нужно опросить # если нужно опросить системные ДНС, оставьте пустое значение $ns='ns1.server.biz' $i=0 while($i -lt $name.length) { nslookup $name[$i] $ns echo '--------------------------------------------------' $i++ }
- Variable declaration (array of strings)
- Variable declaration
- Variable declaration
- A cycle from 0 to the number of lines minus 1 (because
-lt means less, not less or equal) in the first variable (1). I shortened the list, so in this case the cycle will be executed 2 times - Call the command line utility nslookup with the parameters "string from the list
$name " and "DNS server address from the variable $ns ". This utility prints some result to the console. - Output to the console text "----------"
- Increasing
$i by 1 to select the next line in the $name list
The example of the script knocks out the rut by the fact that it mixes not only two examples, but also a different syntax (for the .Net Framework, for the cmdlet, for the command line utility).
I hope that the answer will help to understand Powershell.
nslookup "microsoft.com" "8.8.8.8"and you will not have to build a garden in powershall without need. (nslookup "адрес сайта" "адрес днс сервера") - Andrew B