Which scripting language is the preferred method of performing Windows administration tasks?
Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. What is PowerShell?
In this articlePowerShell is a cross-platform task automation solution made up of a command-line shell, a scripting language, and a configuration management framework. PowerShell runs on Windows, Linux, and macOS. Command-line ShellPowerShell is a modern command shell that includes the best features of other popular shells. Unlike most shells that only accept and return text, PowerShell accepts and returns .NET objects. The shell includes the following features:
Scripting languageAs a scripting language, PowerShell is commonly used for automating the management of systems. It is also used to build, test, and deploy solutions, often in CI/CD environments. PowerShell is built on the .NET Common Language Runtime (CLR). All inputs and outputs are .NET objects. No need to parse text output to extract information from output. The PowerShell scripting language includes the following features:
Automation platformThe extensible nature of PowerShell has enabled an ecosystem of PowerShell modules to deploy and manage almost any technology you work with. For example: Microsoft
Third-party
Configuration managementPowerShell Desired State Configuration (DSC) is a management framework in PowerShell that enables you to manage your enterprise infrastructure with configuration as code. With DSC, you can:
Next stepsGetting startedAre you new to PowerShell and don't know where to start? Take a look at these resources.
PowerShell in actionTake a look at how PowerShell is being used in different scenarios and on different platforms.
FeedbackSubmit and view feedback for Skip to main content This browser is no longer supported. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Get started using Python on Windows for scripting and automation
In this articleThe following is a step-by-step guide for setting up your developer environment and getting you started using Python for scripting and automating file system operations on Windows. Note This article will cover setting up your environment to use some of the helpful libraries in Python that can automate tasks across platforms, like searching your file system, accessing the internet, parsing file types, etc., from a Windows-centered approach. For Windows-specific operations, check out ctypes, a C-compatible foreign function library for Python, winreg, functions exposing the Windows registry API to Python, and Python/WinRT, enabling access Windows Runtime APIs from Python. Set up your development environmentWhen using Python to write scripts that perform file system operations, we recommend you install Python from the Microsoft Store. Installing via the Microsoft Store uses the basic Python3 interpreter, but handles set up of your PATH settings for the current user (avoiding the need for admin access), in addition to providing automatic updates. If you are using Python for web development on Windows, we recommend a different setup using the Windows Subsystem for Linux. Find a walkthrough in our guide: Get started using Python for web development on Windows. If you're brand new to Python, try our guide: Get started using Python on Windows for beginners. For some advanced scenarios (like needing to access/modify Python's installed files, make copies of binaries, or use Python DLLs directly), you may want to consider downloading a specific Python release directly from python.org or consider installing an alternative, such as Anaconda, Jython, PyPy, WinPython, IronPython, etc. We only recommend this if you are a more advanced Python programmer with a specific reason for choosing an alternative implementation. Install PythonTo install Python using the Microsoft Store:
Install Visual Studio CodeBy using VS Code as your text editor / integrated development environment (IDE), you can take advantage of IntelliSense (a code completion aid), Linting (helps avoid making errors in your code), Debug support (helps you find errors in your code after you run it), Code snippets (templates for small reusable code blocks), and Unit testing (testing your code's interface with different types of input). Download VS Code for Windows and follow the installation instructions: https://code.visualstudio.com. Install the Microsoft Python extensionYou will need to install the Microsoft Python extension in order to take advantage of the VS Code support features. Learn more.
Open the integrated PowerShell terminal in VS CodeVS Code contains a built-in terminal that enables you to open a Python command line with PowerShell, establishing a seamless workflow between your code editor and command line.
Install Git (optional)If you plan to collaborate with others on your Python code, or host your project on an open-source site (like GitHub), VS Code supports version control with Git. The Source Control tab in VS Code tracks all of your changes and has common Git commands (add, commit, push, pull) built right into the UI. You first need to install Git to power the Source Control panel.
Example script to display the structure of your file system directoryCommon system administration tasks can take a huge amount of time, but with a Python script, you can automate these tasks so that they take no time at all. For example, Python can read the contents of your computer's file system and perform operations like printing an outline of your files and directories, moving folders from one directory to another, or renaming hundreds of files. Normally, tasks like these could take up a ton of time if you were to perform them manually. Use a Python script instead! Let's begin with a simple script that walks a directory tree and displays the directory structure.
Congratulations! You've just written an automated systems administration script that reads the directory and files you created and uses Python to display, and then print, the directory structure to it's own text file. Note If you're unable to install Python 3 from the Microsoft Store, see this issue for an example of how to handle the pathing for this sample script. Example script to modify all files in a directoryThis example uses the files and directories you just created, renaming each of the files by adding the file's last modified date to the beginning of the filename.
Hope you learned a few fun things about using Python scripts for automating basic systems administration tasks. There is, of course, a ton more to know, but we hope this got you started on the right foot. We've shared a few additional resources to continue learning below. Additional resources
FeedbackSubmit and view feedback for What is a popular language for writing scripts that run in your browser?JavaScript is a lightweight interpreted programming language. The web browser receives the JavaScript code in its original text form and runs the script from that.
Which of the given XSS attacks exploits a vulnerability on the client side?Reflected and stored XSS attacks exploit server-side scripts, while the DOM is used to exploit vulnerabilities in client-side scripts.
Which of the following is a primary vector for attacking applications that will cause these applications to behave in an unexpected way when passing invalid data?the primary vector for attacking applications is to exploit faulty input validation. Input could include user data entered into a form or URL passed by another application or link. Malicious input could be crafted to perform an overflow attack or some type of injection attack.
Which of the following security attacks occurs when an attacker exploits a known vulnerability in an application which could cause another application to crash?A buffer overflow attack occurs when an attacker exploits a known vulnerability in an application (for example, an error in an application that allowed that application to write to an area of memory (that is, a buffer) dedicated to a different application), which could cause another application to crash.
|