This place has just been established, welcome everyone's arrival!
Since it's just the May Day holiday, I估计 there won't be time to write articles in the next few days, but I don't want this place to be empty, so I'll first briefly chat with you about PowerShell.
First, I would like to state that if you are a beginner, you may not fully understand what I'm going to say below, or you are completely a layman in the command line but are very interested in it, then please pay close attention to our forum section. We will compile step-by-step tutorials for beginners so that they can gradually master and use it. The specific writing work of the tutorials will be carried out gradually after the holiday.
Please look forward to it!
PowerShell is Microsoft's next-generation Windows command-line tool. It is a brand-new command line. I roughly read its man page and simply tried a few commands. The strongest feeling I have is "the usage of this new tool is too similar to Python" (Python is an object-oriented scripting language).
We know that traditional shells - such as cmd.exe in Windows XP, its input and output are all text. When we use pipes or redirection to connect several commands, what we pass are all text. But PowerShell is completely different from this. Its input and output are all objects. You may not have object-oriented programming experience. It doesn't matter. Let's first look at a few examples:
Today is May 1, 2006. I only want the year now. In cmd.exe, we can
C:\> echo %date:~0,4%
2006
Use the slicing method to get the first 4 characters. But there is a problem with this method. That is, other ethnic groups may use the writing habit of month/day/year like 05/01/2006. So when the "Regional and Language Options" setting of the system is different, the first 4 characters of the variable date may not necessarily be the year.
But the way in PowerShell is:
PS C:\> ::now.year
2006
is an object with the property now, and now itself has the property year. (Properties are actually similar to variables)
So we get the year in the above way.
If we want to get yesterday's date, in PowerShell:
PS C:\> ::now.adddays(-1)
April 30, 2006 7:29:00
Only the month in yesterday's date:
PS C:\> ::now.adddays(-1).month
4
adddays is called a method of now (methods are actually similar to functions)
If we want to save this month in a variable for future use:
PS C:\> $yestoday=::now.adddays(-1).month
PS C:\> $yestoday
4
If cmd under Windows XP wants to do the same thing (assuming no third-party software is used), generally first slice the year, month, and day into variables respectively, and then write the algorithm by yourself. Since it is necessary to consider that there are 28 days, 30 days, 31 days in a month, and also consider leap years, the algorithm is not very simple.
Maybe you will ask, what exactly are properties and methods, and how should they be used?
Let's take an example: Boy Xiaoming is the sports committee member, Girl Xiaoling is the monitor
Xiaoming, as an object, has the attribute gender, and the value of this attribute is male.
Xiaoming.gender ->male
So when "Xiaoming.gender" appears in the command line, the system will automatically calculate "male".
Similarly, we can use "Xiaoling.name", and the system will automatically calculate "Xiaoling".
Since Xiaoling is the monitor, she can send the instruction "stand up" during class breaks. So Xiaoling has the method "stand up". Using this method will result in all classmates standing up.
Xiaoling.stand up() ->All classmates stand up
For example, convert "this is a string" to uppercase
PS C:\> "this is a string".ToUpper()
THIS IS A STRING
As long as it is a string, it must have the ToUpper() method.
"this is a string".ToUpper() still returns a string object, and we can continue to use the methods of the string.
PS C:\> "this is a string".ToUpper().ToLower()
"this is a string"
That's all for talking about PowerShell today.
[ Last edited by tigerpower on 2006-5-2 at 12:50 ]
Since it's just the May Day holiday, I估计 there won't be time to write articles in the next few days, but I don't want this place to be empty, so I'll first briefly chat with you about PowerShell.
First, I would like to state that if you are a beginner, you may not fully understand what I'm going to say below, or you are completely a layman in the command line but are very interested in it, then please pay close attention to our forum section. We will compile step-by-step tutorials for beginners so that they can gradually master and use it. The specific writing work of the tutorials will be carried out gradually after the holiday.
Please look forward to it!
PowerShell is Microsoft's next-generation Windows command-line tool. It is a brand-new command line. I roughly read its man page and simply tried a few commands. The strongest feeling I have is "the usage of this new tool is too similar to Python" (Python is an object-oriented scripting language).
We know that traditional shells - such as cmd.exe in Windows XP, its input and output are all text. When we use pipes or redirection to connect several commands, what we pass are all text. But PowerShell is completely different from this. Its input and output are all objects. You may not have object-oriented programming experience. It doesn't matter. Let's first look at a few examples:
Today is May 1, 2006. I only want the year now. In cmd.exe, we can
C:\> echo %date:~0,4%
2006
Use the slicing method to get the first 4 characters. But there is a problem with this method. That is, other ethnic groups may use the writing habit of month/day/year like 05/01/2006. So when the "Regional and Language Options" setting of the system is different, the first 4 characters of the variable date may not necessarily be the year.
But the way in PowerShell is:
PS C:\> ::now.year
2006
is an object with the property now, and now itself has the property year. (Properties are actually similar to variables)
So we get the year in the above way.
If we want to get yesterday's date, in PowerShell:
PS C:\> ::now.adddays(-1)
April 30, 2006 7:29:00
Only the month in yesterday's date:
PS C:\> ::now.adddays(-1).month
4
adddays is called a method of now (methods are actually similar to functions)
If we want to save this month in a variable for future use:
PS C:\> $yestoday=::now.adddays(-1).month
PS C:\> $yestoday
4
If cmd under Windows XP wants to do the same thing (assuming no third-party software is used), generally first slice the year, month, and day into variables respectively, and then write the algorithm by yourself. Since it is necessary to consider that there are 28 days, 30 days, 31 days in a month, and also consider leap years, the algorithm is not very simple.
Maybe you will ask, what exactly are properties and methods, and how should they be used?
Let's take an example: Boy Xiaoming is the sports committee member, Girl Xiaoling is the monitor
Xiaoming, as an object, has the attribute gender, and the value of this attribute is male.
Xiaoming.gender ->male
So when "Xiaoming.gender" appears in the command line, the system will automatically calculate "male".
Similarly, we can use "Xiaoling.name", and the system will automatically calculate "Xiaoling".
Since Xiaoling is the monitor, she can send the instruction "stand up" during class breaks. So Xiaoling has the method "stand up". Using this method will result in all classmates standing up.
Xiaoling.stand up() ->All classmates stand up
For example, convert "this is a string" to uppercase
PS C:\> "this is a string".ToUpper()
THIS IS A STRING
As long as it is a string, it must have the ToUpper() method.
"this is a string".ToUpper() still returns a string object, and we can continue to use the methods of the string.
PS C:\> "this is a string".ToUpper().ToLower()
"this is a string"
That's all for talking about PowerShell today.
[ Last edited by tigerpower on 2006-5-2 at 12:50 ]


