PowerShell Management Series (36) PowerShell operations in the statistical domain of computer hardware assets

Source: Internet
Author: User

-----provide ad\exchange\lync\sharepoint\crm\sc\o365 and other Microsoft product implementation and outsourcing, qq:185426445. Phone 18666943750

The client needs to set up a firewall, [note to set the Management template firewall settings first, otherwise the advanced firewall security settings for the default Group Policy will be overwritten]

1, allow remote management, set the following, enable Windows Firewall: Allow the inbound management program

Reference Link: http://908174.blog.51cto.com/898174/1175525

650) this.width=650; "height=" "title=" clip_image002 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image002 "src=" http://s3.51cto.com/wyfs02/M02/8A/25/ Wkiom1gpepza3uixaagdfthk6ag104.jpg "border=" 0 "/>

650) this.width=650; "height=" 498 "title=" clip_image004 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image004 "src=" http://s3.51cto.com/wyfs02/M00/8A/25/ Wkiom1gpep3y9zmvaaeuqoihape706.jpg "border=" 0 "/>

2. Allow Remote Desktop

650) this.width=650; "height=" 434 "title=" clip_image006 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image006 "src=" http://s3.51cto.com/wyfs02/M01/8A/25/ Wkiom1gpep7tamhxaae4djvpcdi897.jpg "border=" 0 "/>

650) this.width=650; "height=" 464 "title=" clip_image008 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image008 "src=" http://s3.51cto.com/wyfs02/M01/8A/22/ Wkiol1gpeqlbxww2aaetwrwy7i0435.jpg "border=" 0 "/>

3. Allow Ping, open Group Policy, Advanced Security firewall settings, inbound rules

650) this.width=650; "height=" 483 "title=" clip_image010 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image010 "src=" http://s3.51cto.com/wyfs02/M00/8A/22/ Wkiol1gpeqwzexsqaad3w2yy36i171.jpg "border=" 0 "/>

4. Choose ICMPv4 and ICMPv6

650) this.width=650; "height=" 488 "title=" clip_image012 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image012 "src=" http://s3.51cto.com/wyfs02/M02/8A/22/ Wkiol1gpeqbafnxtaaehq2z66uo462.jpg "border=" 0 "/>

5. Click Next to finish

650) this.width=650; "height=" 302 "title=" clip_image014 "style=" border:0px;padding-top:0px;padding-right:0px; Padding-left:0px;background-image:none, "alt=" clip_image014 "src=" http://s3.51cto.com/wyfs02/M01/8A/25/ Wkiom1gpeqec1pciaabpd-hog_e567.jpg "border=" 0 "/>

6. Allow PowerShell remote management

Specific Settings Reference Links:

http://yuntcloud.blog.51cto.com/1173839/1790701

The script is as follows:

#统计ip, computer name, user, computer Configuration, host serial number, hard drive serial number, computer model, version of Windows     #防火墙开启windows远程管理, Windows Firewall allows inbound remote management      Import-Module activedirectory                                                       #导入其中的AD   Modules      $computeraccount =get-adcomputer  -filter * -properties * |? {$_. operatingsystem -ne  $null  -and $_.enabled -and  (test-netconnection $_.name| select -expandproperty pingsucceeded)}  '     |select -expandproperty  name          #获取当前AD   All machine NetBIOS names in the computer, excluding disabled, no operating system types, No boot     [email protected] ()     &NBsp;                                                           #定义所有计算机的初始空值     foreach  ($currentcomputename  in $ Computeraccount)                                  #根据计算机对象进行轮询           {              $currentname = get-adcomputer -identity  $currentcomputename |select  -expandproperty name                   #获取机器的NETBIOS名称                 $currentoperatingsystem =  Get-ADComputer -Identity  $currentcomputename  -properties * |select - expandproperty operatingsystem                    #获取机器的操作系统版本                                         $currentclass = get-wmiobject -class win32 _bios -computername  $currentcomputename  -namespace  "root\cimv2"  |select - expandproperty serialnumber                  #通过获取WMI中的bios   class to obtain the corresponding serial number of the machine, stored in the BIOS sn              $currentIP= get-wmiobject -class win32_networkadapterconfiguration -computername $ currentcomputename -filter ipenabled=true |select -expandproperty ipaddress - first 1  '             |? {$_ -notlike  "*:*"  -and $_ -notlike  "169*"}             #通过获取WMI中的IPV4地址                 $currentdiskSN =  get-wmiobject -class win32_diskdrive - computername  $currentcomputename  |select -First 1 -ExpandProperty Model                  #通过获取WMI中的硬盘BIOS序列号              $currentpcmodel =   Get-wmiobject -class win32_computersystem -computername  $currentcomputename  -Property * |select -ExpandProperty Model                  #通过获取WMI中的计算机类型                  $currentmemory =    (get-wmiobject -class win32_computersystem -computername  $currentcomputename  - Property * |select -expandproperty totalphysicalmemory)/1gb -as [int]                 #通过获取WMI中的计算机内存              $currentharddisk =   (get-wmiobject - class win32_diskdrive -computername  $currentcomputename |select -first 1 - Expandproperty size)/1gb  -as [int]                #通过获取WMI中的硬盘大Small                             $computerproperty =new-object  psobject                                                                                                                               #定义一个新PS   Objects               $computerproperty |  add-member -membertype noteproperty -name  "Computer name"  -Value   $currentname                                                                    # Define computer name properties for new objects              $computerproperty |   Add-Member -MemberType NoteProperty -Name  "host serial number"  -Value  $currentclass                                                                       #为计算机对象定义序列号属性             $computerproperty |  add-member -membertype noteproperty -name  "IP Address"  -Value   $currentip                                                                       #为计算机对象定义序列号属性             $computerproperty |  add-member - membertype noteproperty -name  "Hard drive serial number"  -Value  $CURRENTDISKSN                                                                        #为计算机对象定义硬盘序列号属性           $ computerproperty|  add-member -membertype noteproperty -name  "Operating system version"  - value  $currentoperatingsystem                                                                      # Define the operating system version      & for computer objectsnbsp;      $computerproperty |  add-member -membertype noteproperty  -Name  computer type  -Value  $currentpcmodel                                                                        #为计算机对象定义计算机类型                $computerproperty |  add-member -membertype noteproperty -name  "Computer memory size (GB) " -Value  $currentmemory                                                                      #为计算机对象定义计算机内存属性                                                                             $computerproperty |   Add-Member -MemberType NoteProperty -Name  "Computer hard disk size (GB)"  -value $ currentharddisk                                                                     #为计算机对象定义计算机硬盘属性                                                                             $allcomputername = $allcomputername +$ computerproperty                                                                                                                #根据对象的轮询将当前对象的属性加入到哈希数组中                     }                         $tmplogfile = "C:" + "\" +$ (get-date -format  "yyyy-mm-dd") + ". csv"                                                                                                       # Define path and file format for output files              $allcomputername |  export-csv -encoding default -notypeinformation -path  $tmplogfile                                                                               # To export the data as a csv  file, we get the information we want to get directly from the csv  file                   $UserName =  "[email protected]"        #定义发送账户名称               $Password  = ConvertTo-SecureString  "123456"  -AsPlainText –Force             $cred  = new-object system.management.automation.pscredential ($UserName, $Password)               Send-MailMessage -From  "[email  Protected] " -To " [email protected] " -Subject " Computer hardware information summary " -Credential  $cred  -SmtpServer  "mail.yuntcloud.com"  -Attachments  $tmplogfile                '-encoding  ([System.text.encoding]::utf8)


This article is from the "Zhou Ping Microsoft Technology Exchange Platform" blog, please be sure to keep this source http://yuntcloud.blog.51cto.com/1173839/1872504

PowerShell Management Series (36) PowerShell operations in the statistical domain of computer hardware assets

Related Article

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.