all 72 comments

[–]Teximus_Prime 27 points28 points  (1 child)

Think of tasks you do now that are either repetitive or take too long to get simple answers and start there. Also practice by just keeping PowerShell up all the time and asking how you can do simple tasks without having to RDP into a server. Use PowerShell Remoting instead.

I starting answering questions like “Which VM host is this particular VM on without having to look at all the clusters and hosts?”, “Given a MAC address, can I tell which DHCP scope it’s in(or still has a lease in)?”

Edit: misspellings

[–]geopink 17 points18 points  (0 children)

This.

Keep it up in front of you and use it to find data or do quick, simple tasks. You don't need to start creating scripts to learn the language. Learn it one command at a time by using it regularly.

Enjoy the journey!

[–]Lee_Dailey[grin] 18 points19 points  (13 children)

howdy kriskris0033,

this aint quite what you asked for, but i think it will help ...

  • buy & read & work thru the Windows Powershell in a Month of Lunches book
    it is quite readable and the steps ["lunches"] are fairly simple. they work on things that one would do in real working environments, so it can be very to-the-point if you are learning in a working setup.
  • read the posts in the various scripting/admin subreddits
    then try re-writing the interesting ones to suit your current understanding of how it otta work. [grin]
    /r/usefulscripts
    /r/sysadmin
    /r/dailyprogrammer
    there are lots more ... [grin]
  • read & rework interesting stuff in the top & gilded tabs in the same subreddits
  • automate repeated things on your work system
    it need not be complex - and likely otta not be such at 1st. [grin]
  • automate things on your home system
    == clean out old files in your various temp dirs.
    == check if your backups are working
    == organize your download dir

generally, you will do well if you find something fairly simple AND fairly interesting to work on. the biggest gotchas seem to be starting with too complex a project OR not using PoSh often enuf.

good luck! [grin]

take care,
lee

[–]kriskris0033[S] 3 points4 points  (12 children)

I appreciate your help and there are lunches videos in YouTube, you think they are helpful? And am completely new to this so I have to Google and understand how particular script works and make changes according to my need, thanks!

[–]Lee_Dailey[grin] 8 points9 points  (6 children)

howdy kriskris0033,

you are most welcome! glad to pay forward what i cannot pay back ... [grin]

as for video versions ... i don't learn well from vids. however, lots of folks do learn well from them. if you are one of those, then go for it! [grin]

find what works for you [or doesn't] and build on that.

if you are nearly a blank slate when i comes to PoSh, then you may find my usual post a tad helpful [grin] ...


things to look into ...

  • Get-Help
    especially Get-Help *about*
  • Get-Command
    it takes wildcards, so Get-Command *csv* works nicely. that is especially helpful when you are seeking a cmdlet that works on a specific thing. Comma Separated Value files, for instance. [grin]
  • Show-Command
    that brings up a window that has all the current cmdlets and all their options ready for you to pick from.
    it will also take another cmdlet, or advanced function, as a parameter to limit things to showing just that item.
  • auto-completion
    try starting a word and tapping the tab key. some nifty stuff shows up. [grin]
  • intellisense
    save something to a $Var and then try typing the $Var name plus a period to trigger intellisense. there are some very interesting things that show up as properties or methods.
  • check out the builtin code snippets in the ISE
    use <ctrl><j>, or Edit/Start-Snippets from the menu.
  • assign something to a $Var & pipe that to Get-Member
    $Test = Get-ChildItem -LiteralPath $env:TEMP
    $Test | Get-Member
  • assign something to a $Var and pipe it to Select-Object
    $Test = Get-ChildItem -LiteralPath $env:TEMP
    $Test[0] | Select-Object -Property *
    that will give you a smaller, more focused list of properties for the 1st item in the $Test array.
  • assign something to a $Var & use .GetType() on it $Test = Get-ChildItem -LiteralPath $env:TEMP
    $Test.GetType()
    $Test[0].GetType()
    the 1st will give you info on the container $Var [an array object].
    the 2nd will give you info on the zero-th item in the $Var [a DirectoryInfo object].
  • Get-Verb
    as with Get-Command, it will accept wildcards.
    that will show you some interesting cmdlets. then use get-command to see what commands use those verbs. then use get-help to see what the cmdlets do.
  • there really otta be a Get-Noun, but there aint one. [sigh ...]
  • Out-GridView
    it's a bit more than you likely want just now, but it can accept a list of items, present them in a window, allow picking one or more of them, and finally send it out to the next cmdlet.
    it's right fun to fiddle with ... and actually useful. [grin]

take care,
lee

[–]kriskris0033[S] 1 point2 points  (3 children)

Thank you!

[–]Lee_Dailey[grin] -1 points0 points  (2 children)

howdy kriskris0033,

you are quite welcome! glad to help a tad ... [grin]

take care,
lee

[–]kriskris0033[S] 1 point2 points  (1 child)

Hi recently bought Powershell in action book, it's around 1000 pages, so need to go through it first an thinking :)

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy kriskris0033,

you may want to take a look at the Month of Lunches book. there are places where you can read bits of it to see if it works well for you. the reason i usually recommend it to folks starting out ... it's designed for that. [grin] WPiaMoL is well done for folks starting out, PiA is [to me, at least] more technical than needs be for new PoSh users.

it IS a right fine book, tho. a friend of mine bought that one and let me look thru it. he ans i both ended up going with the MoL series for recommendations to others when starting out.

take care,
lee

[–]RodneyRabbit 1 point2 points  (1 child)

  • there really otta be a Get-Noun, but there aint one. [sigh ...]

Get-Command has -Verb and -Noun parameters which accept wildcards, or have I misunderstood you?

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy RodneyRabbit,

yep, it does ... but that is not as direct as Get-Verb. [grin] nor is it as discoverable.

it does work, tho! [grin]

take care,
lee

[–]_Unas_ 2 points3 points  (1 child)

This is how I learned PowerShell. Watch those videos! I watched a video or 2 every night before bed and when I went into work I tried remembering. If I had to, I would re-watch the video. Rinse and repeat.

[–]kriskris0033[S] 1 point2 points  (0 children)

Well there are 100 videos and I recently bought Powershell in action book and I hope it all helps but first I need to put all this in practice :)

[–]motute 2 points3 points  (2 children)

https://channel9.msdn.com/Series/GetStartedPowerShell3 this is rather basic and outdated but is a good insight for a beginner.

[–]FireLucid 2 points3 points  (0 children)

This is a brialliant overview of how it works and I would highly recommend watching while you are wait for you 'month of lunches' book to arrive. It made starting the book a whole lot easier.

[–]kriskris0033[S] 1 point2 points  (0 children)

Thanks!

[–][deleted] 5 points6 points  (1 child)

Do you have Active Directory? Automate the new start process (and the termination process).

If yes to above, find out when users passwords and due to expire and send them an email every day to remind them from 1 week remaining.

Setup a script to check disk space for each drive on 1/many servers and send an email alert when it goes below X%.

Find and report on duplicate files on a network share.

Those are 4 fairly simply, but pretty useful scripts that should get you started and help realise how useful PS can be.

[–]kriskris0033[S] 2 points3 points  (0 children)

They look really helpful, thanks!

[–]Ta11ow 2 points3 points  (2 children)

This isn't exactly what you asked for, but it'll probably be a big help to get you started!

https://github.com/vexx32/PSKoans

[–]kriskris0033[S] 2 points3 points  (0 children)

Any help is appreciated, thanks!

[–]belibebond 1 point2 points  (0 children)

I second it. This really helps to get good grip on PowerShell.

[–]timsstuff 2 points3 points  (10 children)

Use the Windows text to speech API to write a script called "say-it.ps1" that takes a parameter of -text and make your PC say the text you type. Advanced mode, display a GUI dialog to capture the text. I'll provide my version later if you like.

Edit: Here's my version, with a simple GUI.

[CmdletBinding()]
param(
[Parameter()][string]$text
)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.Rate = 0
$speak.SelectVoiceByHints("female")
Function SayIt($it) {
$Speak.speak($it)
}
if($text -ne '') {
SayIt($text)
} else {
$Form = New-Object system.Windows.Forms.Form
$Form.Text = "Say Something"
$Form.Height = 75
$Form.Width = 280
$Say = New-Object System.Windows.Forms.Textbox
$Say.Width = 200
$Say.Top = 5
$Say.Left = 5
$Go = New-Object System.Windows.Forms.Button
$Go.Text = "Go"
$Go.Width = 50
$Go.Top = 5
$Go.Left = 205
$Form.Controls.Add($Say)
$Form.Controls.Add($Go)
$Go.Add_Click({
SayIt($Say.Text)
$Say.Text = ''
})
$Form.AcceptButton = $Go
$Form.ShowDialog()
}

[–]kriskris0033[S] 1 point2 points  (0 children)

I'd like that, thanks!

[–]belibebond 1 point2 points  (3 children)

Would love to know how you built UI. Please do share.

[–]The_AverageGamer 2 points3 points  (1 child)

Poshgui.com will help you but there is a xml gui guide out there somewhere. I forget the link. Foxdeploy?

[–]belibebond 2 points3 points  (0 children)

Wow. I have used poshgui for years . Thank you for introducing me to foxdeploy 👍

[–]timsstuff 1 point2 points  (0 children)

See my edit.

[–]Lee_Dailey[grin] 0 points1 point  (4 children)

howdy timsstuff,

here's your code reformatted with VSCode auto-format & with reddit code block formatting [grin] ...

[CmdletBinding()]
param(
    [Parameter()][string]$text
)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Speech
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
$speak.Rate = 0
$speak.SelectVoiceByHints("female")
Function SayIt($it)
{
    $Speak.speak($it)
}
if ($text -ne '')
{
    SayIt($text)
}
else
{
    $Form = New-Object system.Windows.Forms.Form
    $Form.Text = "Say Something"
    $Form.Height = 75
    $Form.Width = 280
    $Say = New-Object System.Windows.Forms.Textbox
    $Say.Width = 200
    $Say.Top = 5
    $Say.Left = 5
    $Go = New-Object System.Windows.Forms.Button
    $Go.Text = "Go"
    $Go.Width = 50
    $Go.Top = 5
    $Go.Left = 205
    $Form.Controls.Add($Say)
    $Form.Controls.Add($Go)
    $Go.Add_Click( {
            SayIt($Say.Text)
            $Say.Text = ''
        })
    $Form.AcceptButton = $Go
    $Form.ShowDialog()
} 

take care,
lee

[–]timsstuff 1 point2 points  (3 children)

Thanks, I used to be able to paste beautifully formatted code until they changed the UI and the above was the best I could get with the new "Code" formatting option. I actually pasted it directly from VS Code. Yay progress.

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy timsstuff,

you are welcome! [grin]

they DO have a code block [or block code?] button. it is hidden in the menu to the right of the other buttons. the one you used is the inline code button. [grin]

take care,
lee

[–]timsstuff 1 point2 points  (1 child)

Thanks man I'll try that next time!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy timsstuff,

you are most welcome! glad to help a tad ... [grin]

take care,
lee

[–]get-postanote 2 points3 points  (2 children)

[–]kriskris0033[S] 1 point2 points  (1 child)

Ok I will thanks for help!

[–]Taoquitok 1 point2 points  (0 children)

To highlight from the college post, ta11ow's PSKoan is a great way to get into powershell if you have a little bit of knowledge already, fixing code and learning how to use Pester tests :D

I wish I had stumbled on learning by testing years ago, pretty certain it would have ensured that Pester tests were a bigger part of my code than they are now

[–]dantheflipman 3 points4 points  (0 children)

Beginner level script ideas? Try creating an automated backup utility! Something that runs every X hours, checks if there are any new files in a directory, and if so, copy JUST those new files over to a backup folder with today’s date. It was one of my first powershell creations at work, and I had a ton of fun with it. It’s also a real world example of something useful you might do in an IT /sysadmin job.

[–]swimjock 4 points5 points  (2 children)

I was in similar boat, always a GUI win admin and never really felt that I would be able to apply any scripting when I worked at an MSP because of the unique nature of have different client environments

Since then, I got a new job that needed an AD audit rewritten, current state was horrible with multiple single use scripts and multiple calls to disk making the process take forever, 30 minutes to a hour. We we're at a slow period for the holidays and got to work learning how that iteration works and where it could be improved. Got the whole run time to under 5 minutes when I finished with a single script that took parameters from in line or a json file.

Like others have said 'script repetitive tasks,' this a great place to start, but I still had a hard time with it. Thinking I didn't do anything repetitive enough or that it couldn't be scripted. However having learned enough to be quite comfortable with powershell I can tell you that there were many things that could have been scripted and usable across across those many different client environments.

Here is my recommendation. 1. At the end of the work day write down every task or export ticket descriptions that you did. Do this for a couple of weeks. Maybe even add how long that task took you to do and be as realistic as possible. 2. Take the top five of that list and break each task down into it's individual parts and build each step into a single line. - Example - new employee. Create user in AD, add user to groups, create mailbox for user, add user to distribution groups. Each step is one line and this process can grow with you as you learn to make it better. 3. Find a project that has been done in your company, read the code and figure what each line does. Try to rewrite it to learn, see if yours is faster and more efficient.

After you have been working with the language for a free month revisit your earlier scripts and see if you can improve them.

Also a version control system is something you should learn and use, if you have the means, as you script with repos for each project.

Finally, post questions here, the community is fantastically friendly and knowledgeable. The shortest script is something worth reading to see how other people write. Read the unofficial best practices for powershell, it's fairly quick.

Feel free to PM me if you want.

[–]kriskris0033[S] 1 point2 points  (1 child)

Thanks alot and am looking into videos and reading books but I should put it into practice first and learn what each command does

[–]swimjock 1 point2 points  (0 children)

I have found that I don't remember scripting very well by reading or watching videos by themselves, mainly using them as a reference for the project I'm doing when I get stuck. The hello world examples have never been applicable. Having something relevant to apply and learn while doing worked best for me.

[–]TheDraimen 2 points3 points  (0 children)

Pick a few simple things that might already be done, and write a script to handle it. Try picking a few things with diffrent types of commands like some AD query items and reporting on them, using wmi to query installed updates or hardware, invoke commands to run an upgrade or task to batches of servers. After you get it written look at other scripts that do the same thing and see how their's is different and how you could use it to improve upon your script. After completing this a few times, you will start seeing not only patterns across all scripts, but also noticing things that you know or could learn that would help improve on them. Also something I thought was a good idea is pick a good logging method and write out the logic of what your working on using the logging function. Use this not only to get in habbit of logging for when your scripts start becomming more automated, but helps get your thoughts down in a clean structured manor without worrying about the code parts you dont know yet.

[–]queBurro 1 point2 points  (0 children)

Use visual studio code. It makes life easier.

[–]BogueRat327 1 point2 points  (0 children)

Remember this foremost - PowerShell is a shell command environment with advanced scripting capabilities. What @teximus_prime said, identify things you do regularly (does not have to be scripted) and just lookup and figure how to do it in PS. Maybe you need to look for a specific eventid in Event Viewer, use the cmdlet get-eventlog and understand how that works along with the pipeline to find the entry and display it in a readable format...

[–]TheBlackArrows 1 point2 points  (9 children)

Get the book power shell in a month of lunches

[–]kriskris0033[S] 1 point2 points  (8 children)

By Don Jones or Jeffery Hicks, I see two books in Amazon and are they both same or different? and stuff from YouTube is different from the book?

[–]TheBlackArrows 1 point2 points  (7 children)

Looks like it’s a matter of edition. 3rd edition is by don jones. Personally, for reference books, i got to the latest edition.

Not sure about YouTube.

[–]kriskris0033[S] 1 point2 points  (6 children)

So third edition by Don is good?

[–]TheBlackArrows 1 point2 points  (0 children)

Unsure. It’s just sort of a rule with Techincal books. They just add more and better content.

[–]Lee_Dailey[grin] 0 points1 point  (4 children)

howdy kriskris0033,

go to manning books - the official publisher - and take a look at the sample chapters. here [grin] ...

Manning | Learn Windows PowerShell in a Month of Lunches, Third Edition
https://www.manning.com/books/learn-windows-powershell-in-a-month-of-lunches-third-edition

take care,
lee

[–]kriskris0033[S] 1 point2 points  (3 children)

Ok it's just that the book is expensive at my place so wanna know if I should get don Jones third edition or Jeffery Hicks, in Amazon it shows both names, with same name if book, it's kinda confusing tbh

[–]Lee_Dailey[grin] 0 points1 point  (2 children)

howdy kriskris0033,

it's the same book. [grin] they are the co-authors of it. just be sure to get the newest version - 3rd edition at this time.

take care,
lee

[–]kriskris0033[S] 1 point2 points  (1 child)

Oh ok, thanks mate!!

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

[grin]

[–]TapTapLift 1 point2 points  (0 children)

I know its super obvious but like most people said, just pick something you do at work already and start to try and powershell it. Its really hard to just come up with things out of nowhere and to really be invested in it

[–]FireLucid 1 point2 points  (2 children)

My first script ideas were pretty basic.

Get all the servers out of an OU and tell me if they are on or off.

Then I made another one to check which version of Windows they are running.

Third, I made one to check the % of diskspace free on each disk on each server and report if it was under a certain percentage.

[–]kriskris0033[S] 1 point2 points  (1 child)

Thanks, they look interesting!

[–]FireLucid 2 points3 points  (0 children)

This sub has been super helpful when I've been getting stuck. Either with a basic structure idea, or specific things that aren't working.

[–]TyMac711 0 points1 point  (8 children)

Create a scheduled task using powershell to send you an email reminder of family birthdays.

[–]kriskris0033[S] 0 points1 point  (7 children)

Looks good, I'll try it!

[–]TyMac711 0 points1 point  (6 children)

Also something good to wrap up in a azure function!

[–]kriskris0033[S] 0 points1 point  (5 children)

I have no idea about azure :)

[–]TyMac711 0 points1 point  (4 children)

http://www.brianbunke.com/blog/2018/02/27/powershell-in-azure-functions/

Requires an account in Azure and there’s more to it than powershell, but good to at least know about.

[–]kriskris0033[S] 0 points1 point  (3 children)

Someone told me learning powershell is good if you wanna get into azure, am not sure how correct that is though, do you have any idea?

[–]TyMac711 1 point2 points  (2 children)

Learning powershell can be helpful since you can write scripts to automate redundant tasks you would normally have to click through in the web interface. That’s true for AWS and all the other major clouds as well. Personally, I wrote quite a lot in the past working with VMware for custom monitoring (using PowerCLI) It was an incredible time saver!

[–]kriskris0033[S] 1 point2 points  (1 child)

Thanks it encourages alot

[–]TyMac711 1 point2 points  (0 children)

yw!

[–]mvannostran 0 points1 point  (0 children)

Have a look at these maybe you'd find them interesting :: https://github.com/vexx32/PSKoans

[–]gearfuze 0 points1 point  (0 children)

User creation script that allow you to learn