微軟終於宣佈Powershell開源了,也就是可以在Linux和OSX上執行了。
豆子參考這篇博文,簡單的測試了一下。
http://www.howtogeek.com/267858/how-to-install-microsoft-powershell-on-linux-or-os-x/
找了一個CentOS7的服務器,https://github.com/PowerShell/PowerShell/releases/ 這個上面下載對應的rpm文件,然後拷貝到我的/tmp目錄,然後執行yum install的操作
目前的版本還是alpha版本,所以肯定有很多bug,先嚐嚐鮮看看
[root@sydnagios ~]# yum install /tmp/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm Loaded plugins: fastestmirror, langpacks Examining /tmp/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm: powershell-6.0.0_alpha.9-1.x86_64 /tmp/powershell-6.0.0_alpha.9-1.el7.centos.x86_64.rpm: does not update installed package.
等安裝完成之後就可以直接使用powershell了
[root@sydnagios ~]# powershell PowerShell Copyright (C) 2016 Microsoft Corporation. All rights reserved. PS /root>
隨便執行幾條命令試試
比較有趣的是, 我確實可以用ps命令導出結果,甚至也能導入,不過導入的結果不像window裏面把所有的內容自動作爲屬性來保存,而是整個字符串作爲一個屬性,如果要處理這個文件的內容,我還是得和Linux一樣去處理字符串,powershell的對象特性完全沒有體現出來
PS /root> get-process | out-file /tmp/test.csv PS /root> $a=import-csv /tmp/test.csv WARNING: One or more headers were not specified. Default names starting with "H" have been used in place of any missing headers. PS /root> ¥ PS /root> $a | gm TypeName: System.Management.Automation.PSCustomObject Name MemberType Definition ---- ---------- ---------- Equals Method bool Equals(System.Object obj) GetHashCode Method int GetHashCode() GetType Method type GetType() ToString Method string ToString() H1 NoteProperty string H1=Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
另外一個豆子很期待的功能是遠程操作,可惜invoke-command 這個命令根本就不存在,enter-pssession雖然存在,但是執行會報錯,找不到對應的dll文件。我嘗試谷歌了一下這個文件,一條線索都沒有,估計太新了,還沒有人遇見過這個問題。
PS /root> Enter-PSSession -ComputerName sydit01 -Credential ominicom\yli Windows PowerShell credential request Enter your credentials. Password for user ominicom\yli: ********** Enter-PSSession : Unable to load DLL 'libpsrpclient': The specified module could not be found. (Exception from HRESULT: 0x8007007E) At line:1 char:1 + Enter-PSSession -ComputerName sydit01 -Credential ominicom\yli + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Enter-PSSession], DllNotFoundException + FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.EnterPSSessionCommand
總之呢,很開心看見PS開源,也能夠在*ix上執行,不過現在模塊很少,命令總共才300多條,加上各種bug,還不太實用。希望成熟的版本能盡快出來,這樣在蘋果和Linux下也能遠程的管理Windows了。