|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『楼 主』:
[公告][原创]欢迎大家的到来暨PowerShell初步印象
使用 LLM 解释/回答一下
这里刚刚成立,欢迎大家的到来!
由于正值五一假期,估计今后几天没有时间写文章,但也不希望这里是空荡荡的,所以就先简单的跟大家聊一聊PowerShell。
先申明一点,如果您是初学者,下面说的内容您并不是全懂,或者说,您对于命令行根本是个门外汉,但却对它很有兴趣,那么请您随时关注我们这个版块,我们将为初学者编写循序渐进的教程,使之能逐步掌握和使用。教程具体撰写工作将在节后逐步展开。
敬请期待!
PowerShell是微软下一代Windows命令行工具,它是一个全新的命令行,我粗略地读了一下它的手册页,并简单地试了几条命令,给我最强烈的感觉是“这个新工具的用法太像python了”(python是一种面向对象的脚本语言)。
我们知道,传统的shell-比如windows XP中的cmd.exe,它的输入输出都是文本,当我们用管道或者重定向连接几个命令时,我们所传递的都是文本。而PowerShell与之完全不同,它的输入输出都是对象。您可能没有面向对象的编程经验,这不要紧,我们先来看几个例子:
今天是2006年5月1日,我现在只想要年份,在cmd.exe中,我们可以
C:\> echo %date:~0,4%
2006
用切片的方法获得前4个字符。但这种方法有一个问题,那就是其他民族可能用的是05/01/2006的月/日/年的书写习惯,所以当系统的“区域和语言选项”设置不同时,变量date前4个字符未必就是年份。
而在PowerShell中的做法是:
PS C:\> ::now.year
2006
作为一个对象有属性now,now自身又有属性year。(属性其实类似于变量)
于是我们用上面的方法得到了年份。
如果我们要得到昨天日期,可以在PowerShell中:
PS C:\> ::now.adddays(-1)
2006年4月30日 7:29:00
只要昨天日期中的月份:
PS C:\> ::now.adddays(-1).month
4
adddays称为now的方法(方法其实类似于函数)
如果要把这个月份保存在变量中以便以后使用:
PS C:\> $yestoday=::now.adddays(-1).month
PS C:\> $yestoday
4
如果windows XP下的cmd要做同样的事(假设不借助第三方软件),一般先将年、月、日各自切片存入变量,然后再自己编写算法,由于要考虑一个月中有28天、30天、31天,还要考虑闰年,所以算法并不是很简单的。
可能您会问,究竟什么是属性,什么方法,它们要怎么使用?
举个例子:男生小明是体育委员,女生小玲是班长
小明作为一个对象他就有性别这个属性,这个属性的值就是男。
小明.性别 ->男
所以当在命令行里出现“小明.性别”,系统会自动计算出“男”。
类似的我们可以用“小玲.姓名”,系统会自动计算出“小玲”。
由于小玲是班长,在上下课时可以发送“起立”的指令。所以小铃就有“起立”这个方法,使用这个方法的结果就是全班同学站起。
小玲.起立() ->全班同学站起
又比如把"this is a string"转换成大写
PS C:\> "this is a string".ToUpper()
THIS IS A STRING
只要是字符串,就一定有ToUpper()这个方法。
"this is a string".ToUpper()返回的仍然是一个字符串对象,我们还可以用字符串的方法继续下去。
PS C:\> "this is a string".ToUpper().ToLower()
"this is a string"
关于PowerShell,今天就先谈到这里。
Last edited by tigerpower on 2006-5-2 at 12:50 ]
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 ]
|
|
2006-5-1 08:28 |
|
|
doscc
中级用户
  
积分 256
发帖 93
注册 2006-3-26 来自 广东
状态 离线
|
|
2006-5-2 18:18 |
|
|
doscc
中级用户
  
积分 256
发帖 93
注册 2006-3-26 来自 广东
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
新的命令行.用的是对象.不错.
就像在VB家族一样.也是用对象.
New command line. Uses objects. Not bad. Just like in the VB family, also uses objects.
|
|
2006-5-2 18:20 |
|
|
wl00560
银牌会员
    
积分 1384
发帖 709
注册 2005-10-29
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
问一下楼主,powerShell哪儿有下载的?我想学学,就是不要太难了,呵呵。
Ask the original poster, where can I download PowerShell? I want to learn it, just not too difficult, heh.
|
|
2006-5-2 19:49 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
安装Windows PowerShell您需要
1. Windows XP/2003/Vista的操作系统
2. .NET Framework Version 2.0 RTM
微软官方2006年4月25日发布Windows PowerShell预览版(RC1),它的最终正式版有望在今年第四季度发布。
点击进入Windows PowerShell RC1下载页面(需注册)
同一页面上有关于PowerShell帮助文档的链接(“Windows PowerShell RC1 Documentation Pack”)
以及.NET Framework Version 2.0 RTM的链接(“More .NET Framework Downloads”)
除了32位的版本,它还有x64、ia64的版本。
Last edited by tigerpower on 2006-5-2 at 20:58 ]
To install Windows PowerShell, you need:
1. An operating system of Windows XP/2003/Vista
2. .NET Framework Version 2.0 RTM
Microsoft officially released the Windows PowerShell preview version (RC1) on April 25, 2006, and its final official version is expected to be released in the fourth quarter of this year.
Click to enter the Windows PowerShell RC1 download page (registration required)
There is a link to the PowerShell help documentation ("Windows PowerShell RC1 Documentation Pack") on the same page
And a link to .NET Framework Version 2.0 RTM ("More .NET Framework Downloads")
In addition to the 32-bit version, it also has x64 and ia64 versions.
Last edited by tigerpower on 2006-5-2 at 20:58 ]
|
|
2006-5-2 20:35 |
|
|
wl00560
银牌会员
    
积分 1384
发帖 709
注册 2005-10-29
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
原来还在测试啊,那就先等等。
So it's still in testing, then just wait first.
|
|
2006-5-2 21:04 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
支持~~~~太象Bash了~~
Support~~~~It's too much like Bash~~
|
|
2006-5-3 21:46 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
今天才看到微软的下一代命令行用法,感觉这个工具真是强大啊——不知道下个版本的操作系统还支持xp下的所有cmd命令不。
Today I just saw the usage of Microsoft's next-generation command line, and I feel this tool is really powerful - I don't know if the next version of the operating system will still support all cmd commands in XP.
|
|
2006-6-9 08:12 |
|
|
IceCrack
中级用户
   DOS之友
积分 332
发帖 168
注册 2005-10-6 来自 天涯
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
呵呵 暂时还用不上。很多命令,现在的机子应该是不支持的。那个支持对像真的很不错
Hehe, not needed for the time being. Many commands, the current machines should not support. That support object is really very good
|
|
2006-7-13 07:44 |
|
|
willsion
高级用户
   
积分 793
发帖 312
注册 2004-9-2
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
功能强大,不错。
感觉有点像C语言的“结构”部分。
Last edited by willsion on 2006-7-31 at 13:20 ]
Powerful function, not bad.
It feels a bit like the "structure" part of the C language.
Last edited by willsion on 2006-7-31 at 13:20 ]
|
|
2006-7-31 13:11 |
|
|
shayulei
中级用户
  
积分 301
发帖 74
注册 2005-2-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Windows PowerShell的帮助文件不会用,所以Windows PowerShell不会用
The help file of Windows PowerShell is not used, so Windows PowerShell is not used
|
|
2006-10-6 09:29 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
和楼上的有同感。不过现在 Power Shell 已经作为 微软 Script Center 的一部分了,足以可见PowerShell的重要性
I have the same feeling as the person above. But now Power Shell has become a part of Microsoft Script Center, which is enough to show the importance of PowerShell
|

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>" |
|
2006-10-8 05:44 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
顶一下先``
下一代的命令提示功能更强大了,支持~~~
Bump first``
The command prompt function of the next generation is more powerful, supporting~~~
|
|
2006-10-8 06:18 |
|
|
6622186
高级用户
   
积分 894
发帖 411
注册 2007-2-17
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
我下了, 还要 .net 的支持, .net 要二十二 M, 看了帮助, 不太懂, 就是什么对象, 还有什么别名, 后来不知怎么 .chm 文件 受限用户无法打开, 就把 .net 卸载了.
I downloaded it, but it also requires .NET support. The .NET is 22MB. After looking at the help, I didn't understand it. It was about objects and aliases. Then somehow the .chm file couldn't be opened by restricted users, so I uninstalled the .NET.
|

@set c= 不知则觉多,知则觉少,越知越多,便觉越来越少. --- 知多少.
@for,/l,%%i,in,(1,1,55)do,@call,set/p=%%c:~%%i,1%%<nul&ping/n 1 127.1>nul
|
|
2007-4-25 10:54 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
汗,先下载.net然后安装Powershell就行了啊,不用管.NET的,Powershell可以直接用。
Oh, just download .NET first and then install PowerShell. You don't need to worry about .NET; PowerShell can be used directly.
|
|
2007-4-28 18:12 |
|