1. 程式人生 > >Powershell學習筆記:(一)、初識Powershell

Powershell學習筆記:(一)、初識Powershell

什麼是Powershell?

MSDN上的說明是:PowerShell 是構建於 .NET 上基於任務的命令列 shell 和指令碼語言。 PowerShell 可幫助系統管理員和高階使用者快速自動執行用於管理作業系統(Linux、macOS 和 Windows)和流程的任務。

使用 PowerShell 命令可以從命令列管理計算機。 PowerShell 提供程式可讓你訪問資料儲存(如登錄檔和證書儲存),與你訪問檔案系統一樣方便。 PowerShell 具有豐富的表示式分析器和完全開發的指令碼語言。

個人理解為Powershell就是一門指令碼語言,類似於Linux下的shell語言。與傳統cmd命令不同的是,Powershell不僅能呼叫cmd下的命令,還增加了非常多的新命令,同時Powershell面向物件的(基於.Net)。

使用PowerShell可以完成許多自動化管理。PowerShell增加了對Windows10、Window Server2016、SQL Server、Azure的管理模組。Windows PowerShell是開源的,我們可以在Github上找到它的原始碼

https://github.com/PowerShell/PowerShell

 

啟動Powershell

1、開始選單=》執行=》輸入Powershell

2、開始選單=》Windows Powershell =》 Windows Powershell

 

整合開發環境

1、Windows PowerShell ISE

Windows Powershell ISE全稱是Windows PowerShell Integrated Scripting Environment (ISE) ,翻譯過來就是Windows PowerShell整合指令碼環境,使用它,可以使用Windows PowerShell控制檯中不可用的方式編寫,執行和測試指令碼。 ISE添加了語法著色,選項卡完成,IntelliSense,視覺化除錯和上下文相關幫助。

位於 開始選單=》Windows Powershell 目錄下

 

2、VisualStudio中的PowerShell擴充套件

安裝Powershell擴充套件

PowerShell Tools for Visual Studio 2017

https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2017-18561

PowerShell Tools for Visual Studio 2015

https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2015

PowerShell Tools for Visual Studio 2013

https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2013

下載完成後,雙擊進行安裝。安裝完成後,再使用VisualStudio新建專案時,可以看到已經可以建立Powershell專案

建立專案完成後,在專案上單擊右鍵-》新增-》新建項,選擇“PowerShell Script”,單擊確定。就可以開始編輯PowerShell指令碼

VisualStudio中的PowerShell也具有IntelliSense功能。

指令碼編輯完成以後,可以全部執行,也可以選擇執行指定的指令碼

如果沒有看到輸入,可以選擇檢視=》輸出選單,來開啟輸出視窗。

 

 專案地址:https://github.com/zhaotianff/PowerShellManual