Windows Powershell Create an array _powershell

Source: Internet
Author: User
Tags arrays datetime

You can use commas to create arrays in PowerShell.

PS c:powershell> $nums =2,0,1,2
PS c:powershell> $nums
2
0
1
2

For a sequential array of numbers, you can use a faster method

PS c:powershell> $nums =1..5
PS c:powershell> $nums
1
2
3
4
5

Polymorphism of arrays
Like a variable. If the type of an element in an array is a weak type, the default can store different types of values.

PS c:powershell> $array = 1, "2012 End of the World" ([System.guid]::newguid ()), (get-date)
PS c:powershell> $array
1
2012 World Doomsday

Guid
----
06a88783-a181-4511-9e41-2780ecbd7924

displayhint:datetime
Date    : 2011/12/9 0:00:00
Day     : 9
dayofweek  : Friday
dayofyear  : 343
Hour:
Kind: local
millisecond:910
Minute: Month    :
Second   :
Ticks    : 634590369459101334
TimeOfDay  : 14:15:45.9101334 year:
DateTime  : December 9, 2011 14:15:45

Empty arrays and group of cell primes
Empty array

PS c:powershell> $a =@ ()
PS c:powershell> $a-is [array]
True
PS c:powershell> $a. Count
0

An array of 1 elements

PS c:powershell> $a =, "Moss"
PS c:powershell> $a-is [array]
True
PS c:powershell> $a. Count
1

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.