Explore PowerShell (eight) array, hash table (with: Copy and paste technique) _powershell

Source: Internet
Author: User
Tags lenovo

The arrays that we often use in programming are also commonly used in scripts. This section describes the array in more detail, and the use of the hash table in PowerShell.

Array

In PowerShell, when declaring a variable as an array, you need to use the symbol "@", for example:

$strUsers =@ ("user1","User2", "user3") <enter>

In this way, we declare an array with 3 members. View its values, using:

$strUsers <enter>

There are other operations, such as counting the number of members of an array:

$strUsers. Count <enter>

View or assign a value to an array member individually (note that PowerShell, like most programming languages, has the following index counting starting from 0):

<enter>

<enter>

You can also use the plus sign to merge arrays, such as:

Hash table

A hash table, which is a dictionary, is a very good data structure that allows us to query using keywords, and it has little performance loss because its basic structure is well matched to the computer's storage operations.

When declaring a hash table variable, you also need to use the symbol "@", such as:

$age =@{} <enter> "Marui"=21;" Lee "=27;" Tom "=53

Similar to arrays, there are also the following actions:

Copy Code code as follows:

Inquire
$age ["Marui"] <enter>

Add (note that the increment must be assigned at the same time, otherwise no new entries will be added)
$age ["Ma"]=24 <enter>

Modify
$age ["Ma"]=25 <enter>

Delete (note, use parentheses)
$age. Remove ("Ma") <enter>

Clear Hash Table
$age. Clear () <enter>


The content of this section is very simple, just here. Thank you for taking the time to browse my blog!

After going down, someone asked me in the PowerShell how to copy and paste, in fact, the method is very simple, using the right mouse button on it.

Copy

I use a cmdlet to view the BIOS information and copy it:

Get-wmiobject-class Win32_BIOS <enter>

Step 1:

Select what you want to copy directly using the left mouse button

Step 2:

The right mouse button is copied in the selected area.

Now paste it into here:

SMBIOSBIOSVERSION:7UET82WW (3.12)
Manufacturer:lenovo
Name:ver 1.00PARTTBL (
Serialnumber:r8rngg3
version:lenovo-3120

Paste

Step 1:

Copy content, please try copying the following script content (this script is used to view BIOS details):

Copy Code code as follows:

$info = Get-wmiobject-class win32_bios-namespace root\cimv2-comp.
foreach ($objItem in $info) {
Write-host "BIOS characteristics:" $objItem. Bioscharacteristics
Write-host "BIOS Version:" $objItem. biosversion
Write-host "Build Number:" $objItem. BuildNumber
Write-host "Caption:" $objItem. Caption
Write-host "Code Set:" $objItem. CodeSet
Write-host "Current Language:" $objItem. Currentlanguage
Write-host "Description:" $objItem. Description
Write-host "Identification Code:" $objItem. Identificationcode
Write-host "installable Languages:" $objItem. installablelanguages
Write-host "Installation Date:" $objItem. InstallDate
Write-host "Language Edition:" $objItem. languageedition
Write-host "List of Languages:" $objItem. listoflanguages
Write-host "Manufacturer:" $objItem. Manufacturer
Write-host "Name:" $objItem. Name
Write-host "Other Target operating System:" $objItem. OtherTargetOS
Write-host "Primary BIOS:" $objItem. Primarybios
Write-host "Release Date:" $objItem. ReleaseDate
Write-host "Serial number:" $objItem. serialnumber
Write-host "SMBIOS BIOS Version:" $objItem. smbiosbiosversion
Write-host "SMBIOS Major Version:" $objItem. smbiosmajorversion
Write-host "SMBIOS Minor Version:" $objItem. smbiosminorversion
Write-host "SMBIOS Present:" $objItem. smbiospresent
Write-host "Software Element ID:" $objItem. Softwareelementid
Write-host "Software Element State:" $objItem. softwareelementstate
Write-host "Status:" $objItem. Status
Write-host "Target operating System:" $objItem. TargetOperatingSystem
Write-host "version:" $objItem. Version
Write-host
}

Step 2:

Click the right mouse button in the PowerShell.

Look at the results:

Then enter the execution, you see the results.

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.