注:本文来自博客园用户的投稿。
作者:PowerShll 传教士
问:微软的 PowerShell 脚本语言已经开源了 ?
答:绝对真的!已经!
问:源码在哪?
答:微软 .net 源码网站。http://referencesource.microsoft.com/
问:为什么在那里?
答: powershell 本身是基于 .net 的。是【System.Management】其中的一个类。
问:powershell 源码如何看?
答:在 namespaces 搜索栏输入
System.Management.Automation.PowerShell
System.Management.Automation.ScriptBlock
等。
问:powershell 有什么特色?
答:cmd(bat)中有命令行管道。vbs 中有面向对象。 powershell 相当于 bat vbs。既有命令行和管道,又有面向对象。并极大增强了命令。相当于 linux 中的 bash python。
面向对象比字符串增加了属性和方法。 返回的属性,比字符串粒度更小,更严禁细致。让你写脚本不用扣字符串。 方法让你不用编程,就有相关功能。
问:能否介绍下 windows 命令行的历史?
答:
win2000 时代:基本上只有图形功能,而对应的命令缺失。
win2003 时代:图形功能,基本都有对应的命令。但只限于 win。
win2008 时代:除了 win 之外的微软软件中。图形功能,而对应的命令基本全了。但还都是面向字符串的。
win2012 时代:重新造所有轮,用所有 powershell 命令代替所有字符串命令。使 windows 命令行全面进化到【面向对象】阶段。
winxp:cmd 命令行。
win7:基本 powershell。
win8.1:全面【面向对象】。
win10:更全面,连剪贴板都面向对象了!
问:powershell 的缺点是什么?
答: 依赖高版本 windows。
问:兼容老版 CMD?
答:
1 语法不兼容 cmd 和 bat。powershell 语法更佳。
2 所有外部命令都兼容。比如 ping.exe 等。
问:powershell 源码的字体和配色,看起来有点矮丑挫,咋办?
答:用 powershell ise 高大上 【字体 配色文件】。 http://www.cnblogs.com/piapia/p/3987305.html
问:powershell 比 CMD(bat)强在哪?
答:
- 语法方面。语法简单。有函数,功能强大。
- 有正则,有查找,替换,切割,有大字符串对象,更适合于处理字符串。
- 有多线程并发,多进程并发。有计时器。有图形界面。
问:powershell 比 python 如何?
答:
1、python 可以跨平台,powershell 暂时不能,这是缺点。
2、powershell 为 win 峰。win 本地深耕比 python 深。而 python 有些独有的 linux 功能 powershell 没有。
- 有管理 dns 服务器,dhcp 服务器,打印机,网卡,域服务器,exchange 服务器管理命令。这些 python 不行。
- .net 内置图形界面【System.Windows.Forms】powershell 开发图形界面比 python 容易。
3、手册中文,开发工具中文,调试功能佳。不容易乱码等。
问:powershell 比 linux bash 如何?
答:
- bash 中没有属性方法,python 中没有管道命令行。假如 python 带有命令行管道,bash 跪不?
- bash 中有多线程,计时器,图形界面?
问:我听说 linux 命令比 win 多,更全,对么?
答:
win 中命令更多,更全面,linux 不行。
1 powershell 命令比 linux 多得多。
2 linux 软件中,很多命令缺失。不能【修改软件运行时的配置】。
2. 1 上述 exchange 服务器,命令手册在: https://technet.microsoft.com/zh-cn/library/bb124413.aspx 500 多条命令,哪个 linux 邮件服务器能比?
2. 2 给 bind 服务器中的一个 dns 域中的一个域名,添加一个 ip。如何用命令实现?
3 linux 软件依赖配置文件,但是有些命令只能【修改软件运行时的配置】。而没有【导出单个配置到文件】,【导出所有配置到文件】的功能。
3. 1 win2012 中的 iis 管理命令中有 Backup-WebConfiguration,Clear-WebConfiguration,Get-WebConfiguration,Restore-WebConfiguration。这些命令今年出的 nginx 中有对应的命令么?
问:powershell 能管理 linux 么?
答: 可以的。
powershell 的做法是外部合作,而不是内部取代 bash。
1 通过【powershell dsc】或【powershell sftp 客户端】来推拉配置文件。
2 通过【ssh 客户端模块】,模拟 linux 终端。远程调用 linux 内置的 bash,python 等,返回结果。
问:我只有 winxp,2001 年出的,没装 powershell,没有 curl,就没法用 powershell 了吧?
答: 可以的。
还是用外部合作的办法。通过 http (s),用b/s的方法访问。
1 找一台有高版本 win 的电脑或虚拟机,在上面安装上支持 powershell 的 http 服务器。如: http://www.poshserver.net/ 这个软件支持 http,https,php,powershell,自定义端口,win 认证。
2 在 bat 中用 mshta ( http://powershell 服务器 ip/xxx.ps1 "get-date" ) 之类的命令即可。
问:powershell 的强项优势是什么?
答:
1 .net 在 win 中的性能【应该最佳】,强于 java 和 python。用同样语句,用同样对象的 powershell 脚本,我测了几个,比 py 稍快。(未做定论)个人认为是虚拟机优化的最好的原因。
2 开发 winform,wpf 图形界面。或者即是命令行,又是图形程序。(类似于 ghost.exe)
3 powershell 多线程可以用多核。
4 win 系统管理最强,绝大数微软软件。
5 管理 vmware,微软云,亚马逊云,和云中的虚拟机。
问:将来 powershell 会进入安卓,mac osx 么?
答: 不知道。
但 powershell 会进入物联网系统。win11 iot?将来树莓派应该可以用上。
总结
面向字符的这只脚(本语言)被【面向对象的脚】踩的死死的,终将被淘汰。 这天下将是 python 和 powershell 的!你不玩面向对象,都不好意思说你是玩脚本的。