Download presentation
Presentation is loading. Please wait.
1
Windows Administration using Python
9/11/2018 1:35 PM THR2232 Windows Administration using Python Neil McIsaac Technology Ninjaneer and Trainer @neilmcisaac © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
2
Session Objectives Introduce Python as a system administration tool
How to get started administering Windows 10 with Python The Takeaway Resources and roadmap on how to get started Do it in 20 minutes! * Based on version Python 3.6.2, but will work on most versions
3
The Problem least amount of effort?
9/11/2018 1:35 PM The Problem How can we get the most out of automation with the least amount of effort? © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
4
A Solution… Python? Everything! Python PowerShell Chef/Puppet Focus
9/11/2018 1:35 PM A Solution… Python? Python PowerShell Chef/Puppet Focus Everything! Scripting (Microsoft and Linux/Unix support) Configuration Management Best feature Language simplicity and extensibility Cmdlet simplicity Cross-platform support Worst feature Navigating the ecosystem Extensibility beyond Microsoft built modules Requires Infrastructure support © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
5
Scenarios What? Assess/Evaluate - Service/process information, installed software etc Modify - Start/stop services, install software, modify configuration Where? Local administration or remote administration? Are we using an API such as WinRM or WMI? Where do we need Python installed?
6
Getting Started Install Python (recommend version 3)
Only required where you run python scripts! Virtualenv/venv recommended Install the required packages using pip pip install <package name> Configure WinRM on remote machines WinRM quickconfig Advanced configuration
7
Python Standard Libraries
platform platform.system() – returns windows platform.release() – returns 10 platform.version() – returns platform.win32_ver() – returns OS release, version, sp level and OS type os os.getcwd() – returns current working directory os.chdir(“f:\”) – change to the root of F drive os.system(“Notepad.exe”) – start notepad
8
Python Standard Libraries
shutil – high-level file operations (copy, move etc.) Copies Metadata Copies Permissions Can Specify Buffer shutil.copy(src, dst) No Yes shutil.copyfile(src, dst) shutil.copy2(src, dst) shutil.copyfileobj(src, dst, bufferLength)
9
Packages pywinrm – Python library for Windows Remote Management
Allows for specific WinRM authentication (Kerberos, NTLM, CredSSP) win32core - Python extensions for Windows Supports pip install and replaces Pywin32 win32compat, win32ext, win32gui WMI - Windows Management Instrumentation Requires win32core and win32compat *or* Pywin32
10
WMI Example import wmi c = wmi.WMI()
svcs = c.Win32_Service(StartMode=“Auto”, State=“Stopped”) if svcs: for s in svcs: print(s.Name, “ - ”, s.Caption) else: print “No stopped services”
11
WMI Remote Example import wmi c = wmi.WMI(computer=“computername",
user=“neil”,password=“password”) svcs = c.Win32_Service(StartMode=“Auto”, State=“Stopped”) if svcs: for s in svcs: print(s.Name, “ - ”, s.Caption) else: print “No stopped services”
12
Demo
13
Further Information Python Docs WMI cookbook
WMI cookbook PyWin32 (win32core, win32compat, win32ext) General Windows administration with Python info
14
Please evaluate this session
Tech Ready 15 9/11/2018 Please evaluate this session From your Please expand notes window at bottom of slide and read. Then Delete this text box. PC or tablet: visit MyIgnite Phone: download and use the Microsoft Ignite mobile app Your input is important! © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.