- Microsoft Exchange Server PowerShell Essentials
- Biswanath Banerjee
- 254字
- 2021-07-16 13:04:58
Writing a basic script
Now that we have covered the basics of Windows PowerShell, let's write our first script. PowerShell uses the .ps1
format to save scripts. Before we get into executing scripts, let's first understand the following PowerShell Script Execution Policies that are in place to prevent unwanted scripts from being executed on your computer.
The cmdlet Set-Execution
Policy helps you to change the Policy of which scripts you can run on your computer. There are four different execution policies:
- Restricted: In this mode, you cannot run any script and can use Windows PowerShell to run cmdlets in the interactive mode only.
- AllSigned: Locally created and those signed by a trusted publisher can be run
- RemoteSigned: Scripts downloaded from another computer can run only if these are signed by a trusted publisher
- Unrestricted: All the scripts will run regardless of whether they are signed or not
Now, let's set the execution Policy to Remote Signed and verify using Get-Execution Policy cmdlet:
PS C:\> Set-ExecutionPolicy RemoteSigned PS C:\> Get-ExecutionPolicy
I am going to introduce the PowerShell Integrated Scripting Engine (ISE) that makes it easier to run scripts with features, such as syntax-coloring
, tab completion
, IntelliSense
, visual debugging, and context sensitive Help, as compared to the PowerShell console.
The following script will query the win32_logical
disk WMI
class. This is a representation of a local storage device on a Windows Computer. There are six possible Drive Types, and we will use a Switch statement to get the output in text describing the type of storage:

- 數據科學實戰手冊(R+Python)
- 深入實踐Spring Boot
- Git高手之路
- Python進階編程:編寫更高效、優雅的Python代碼
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- 高級C/C++編譯技術(典藏版)
- Hands-On Enterprise Automation with Python.
- Mastering Drupal 8 Views
- Node.js全程實例
- 精通Python自動化編程
- Tableau 10 Bootcamp
- Geospatial Development By Example with Python
- C++ Fundamentals
- Go語言底層原理剖析
- 游戲設計的底層邏輯