Today, a buddy asked me if I would use Powershell to implement the script. I haven't written the script for a long time. It still takes some time to collaborate and debug the script. After debugging, there is no problem with the operation, you can refer to the following script to enrich the things that your enterprise needs to do. The script code is as follows:
# Requires-version 2
# Script writer: Xu Peng if you need the script, Please mail to the 10853913@qq.com, for me to write the script to create some opportunities, improve faster.
Param
(
$ Templogpath = "c :\"
# Define the default path of the generated file
)
Import-Module ac *
# Import the AD Module
$ Computeraccount = (Get-ADComputer-Filter *-resultsetsize 11000). name
# Obtain the NETBIOS names of all machines in the Active Directory
$ Allcomputername = @()
# Define the initial null values of all computers
Foreach ($ currentcomputename in $ computeraccount)
# Round Robin Based on Computer objects
{
$ Currentname = (Get-ADComputer-Identity $ currentcomputename). name
# Obtain the machine's NETBIOS Name
$ Currentclass = (Get-WmiObject-class Win32_BIOS-computername $ currentcomputename-namespace "root \ cimv2"). SerialNumber
# Obtain the serial number of the machine by obtaining the bios class in WMI and storing the SN of the BIOS
$ Computerproperty = New-Object psobject
# Define a new PS object
$ Computerproperty | Add-Member-MemberType NoteProperty-Name "computer Name"-Value $ currentname
# Define the computer name attribute for the new object
$ Computerproperty | Add-Member-MemberType NoteProperty-Name "Serial Number"-Value $ currentclass
# Define the serial number attribute for a computer object
$ Allcomputername = $ allcomputername + $ computerproperty
# Add the attributes of the current object to the hash Array Based on Object polling
}
$ Tmplogfile = $ templogpath + "\" + $ (get-date-Format "yyyy-MM-dd") + ". csv"
# Define the path and format of the output file
$ Allcomputername | Export-Csv-Encoding default-NoTypeInformation-Path $ tmplogfile
# Export data to a csv file. We can directly obtain the expected information through the CSV file.
Save the above file as ps1, and then run it.
The generated text file CSV is as follows:
This file can also be expanded as needed. You can customize it as needed!