Writing a Powershell Script
I'm not even going to try and re-write any of the wonderful articles out on the web, but I will make suggestions on where you can find great practice materials to practice reading PowerShell.
I believe that reading scripts and code is the best way to find the really cool stuff about a language. Scripting /coding is an art form more than a science because there is no one way to skin a cat. By reading code written by other people, you start to learn techniques and develop questions about how something works. More often than not you will spend a lot of time asking, why the idiot did it that way. That is until you finish the entire script and realize how genius the code actually is.
One final thing before you hop on over to this article to find your first PowerShell script exercise. To make the most out of this exercise you will need to first learn how to start a service as another user. follow the steps laid out below.
The following steps were performed on Powershell 5.1.
There are 3 different ways to accomplish the same goal here, but all of them first require that you are running PowerShell as an administrator.
Note: We provide the command "$null" null values so that no other parameters are changed. It is also important to get a returnvalue of "0" zero. If the retunvlaue is anything else please check out this artlce to find out what may have gone wrong: https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/startservice-method-in-class-win32-service
Before the change |
After the change Method 2 This method is pretty straightforward, and it demonstrates the power of CIMInstance over WMIObject. |
Method 3
This method will only work in PowerShell version 6+.
Set-Service -Name tapisrv -Credential $credential
Note: The $credential is a variable that represents a user's log-in information. Something like the image below:
Everything is encrypted and saved in the variable once the password is captured |
Leave a comment below if you find even better scripts for beginner exercises.
Your Exercise
https://www.networkadm.in/use-powershell-to-find-windows-svcs-configured-to-run-as-another-user/
If you are looking for more advanced scripts try out the link below. Here you will find entire modules built to increase Powershell functionality. Yes, Powershell is modular and can be expanded to handle myriad situations. Best of all, anyone can write a new module and provide it to the entire community. Even YOU!
Comments
Post a Comment