Today a buddy asked me if I realized it with PowerShell. I have not written a script for a long time, the collaboration and debugging of the script is a bit of a while, perhaps debugging the next. Operation is not a problem, you can participate in the following script to enrich your business needs to do some things, script code such as the following:
#requires-version 2
#脚本撰写人: Srinivasan If you need a script, send an email to [email protected] and create some opportunities for me to write a script. Improve faster.
Param
(
$templogpath = "c \"
#定义生成的文件的默认路径
)
Import-module ac*
#导入当中的AD Module
$computeraccount = (Get-adcomputer-filter *-resultsetsize 11000). Name
#获取当前AD all machine NetBIOS names in the computer
[Email protected] ()
#定义全部计算机的初始空值
foreach ($currentcomputename in $computeraccount)
#依据计算机对象进行轮询
{
$currentname = (get-adcomputer-identity $currentcomputename). Name
#获取机器的NETBIOS名称
$currentclass = (get-wmiobject-class win32_bios-computername $currentcomputename-namespace "root\cimv2"). SerialNumber
#通过获取WMI中的bios class Gets the serial number of the machine corresponding to the SN in the BIOS
$computerproperty =new-object PsObject
#定义一个新PS Object
$computerproperty | Add-member-membertype noteproperty-name "Computer name"-value $currentname
# define machine Name properties for new objects
$computerproperty | Add-member-membertype noteproperty-name "serial number"-value $currentclass
#为计算机对象定义序列号属性
$allcomputername = $allcomputername + $computerproperty
#依据对象的轮询将当前对象的属性增加到哈希数组中
}
$tmplogfile = $templogpath + "\" +$ (Get-date-format "yyyy-mm-dd") + ". csv"
#定义输出文件的路径和文件格式
$allcomputername | Export-csv-encoding Default-notypeinformation-path $tmplogfile
#将数据导出为csv file, we'll get the information we want directly through the CSV file.
Save the above file as PS1, and then after we execute it.
The resulting text file for CSV such as the following:
This file can also be based on the needs to do some expansion, we can do according to the needs of some of their own customization!
Using PowerShell to obtain information about the resources of the company's internal machines is the basic way for the enterprise to manage assets.