Using Powershell to obtain the resources of the company's internal machines is the basic way for the enterprise to manage assets in the future!

Source: Internet
Author: User

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!

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.