Collect client MAC addresses using PowerShell

Source: Internet
Author: User

To share a PowerShell script used on a project, there are some very simple PowerShell statements that are designed to collect the MAC address on each client machine and then output it to a Notepad file. The script that is shared in this example is to output the results to the client's desktop and, of course, can be entered uniformly into a file server for statistical convenience. Look at the script content below

import-module netadapter$path = [environment]:: GetFolderPath ("Desktop")  +  "\macaddress.txt" add-content  $path   $env:computername  With the following network adapters, the MAC addresses are: ' R ' n ' $rules  =  ' \b[0-9,a-z]\b ' foreach  ($id  in  (get-netadapter). InterfaceIndex) {$name  =  (get-netadapter -interfaceindex  $id). name$count = 0for   ($i  = 0;  $i  -lt  $name .length;  $i + +) {if  ($name [$i] -notmatch   $rules  -and  $name [$i] -ne     -and  $name [$i] -ne  "("  - and  $name [$i] -ne ] ") {$count + +}} $length  = 30 -  $name. length - $ countadd-content  $path   $name  $ ('   '  * $length)   mac address is: $ ((get-netadapter  -InterfaceIndex  $id). MacAddress) "}add-content  $path  " =================================================================== " 


This script tells the truth that there is nothing to say in terms of grammar, it's very simple syntax.

But I think the only thing that's hard to say is that the output to Notepad for Chinese is well known because Chinese is two characters in character, so the text that I output to Notepad can never be aligned anyway, so it's awkward to look at it. If the adapter name is Chinese, you will see this line will be more than the other English lines protruding to some, this effect is quite disgusting for an obsessive-compulsive disorder, this can not endure, tried all kinds of coding methods have no way to solve, it seems only to judge the! Here to use a simple formal expression to determine whether it is English, because the expression does not include () and space, so only in the later statements added to this part of the judgment, the overall can be distinguished from the adapter name in the Chinese and English, with such a logical statement, the output of neat content is no longer what the problem. If you are interested, you can try directly to output the results to notepad what effect.

This is the introduction of this, I hope to have even a little bit of help to everyone

This article is from the "Just Make It Happen" blog, so be sure to keep this source http://mxyit.blog.51cto.com/4308871/1658116

Collect client MAC addresses using PowerShell

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.