0%

0/1 Lessons

Course Introduction

• 5min

0 / 2 lessons complete

Getting Started with Windows PowerShell

• 56min

0 / 8 lessons complete

Getting Help and Finding Commands

• 39min

0 / 6 lessons complete

PowerShell Command Syntax

• 33min

0 / 5 lessons complete

PowerShell Objects and Properties

• 35min

0 / 6 lessons complete

The PowerShell Pipeline

• 24min

0 / 2 lessons complete

PowerShell Providers

• 30min

0 / 5 lessons complete

PowerShell Arrays and Variables

• 28min

0 / 4 lessons complete

PowerShell Loops

• 19min

0 / 3 lessons complete

PowerShell Conditional Statements

• 11min

0 / 1 lessons complete

On Premises Lab Setup

• 36min

0 / 8 lessons complete

Basic Domain Administration with Windows PowerShell

• 2hr 27min

0 / 10 lessons complete

Send Emails with PowerShell

• 22min

0 / 2 lessons complete

PowerShell Desired State Configuration (DSC) Basics

• 1hr 48min

0 / 6 lessons complete

PowerShell Modules

• 58min

0 / 7 lessons complete

Powershell Challenges

• 1hr 55min

0 / 23 lessons complete

Section Overview
Full Access Account Required

Video | 5 min

The Trusted Hosts List Challenge
Full Access Account Required

Text | 5 min

The Trusted Hosts List Answer
Full Access Account Required

Video | 5 min

Starting a Remote Session Challenge
Full Access Account Required

Text | 5 min

Starting a Remote Session Answer
Full Access Account Required

Video | 5 min

Rename a Computer Challenge
Full Access Account Required

Text | 5 min

Rename a Computer Answer
Full Access Account Required

Video | 5 min

Change a Password on a Remote Computer Challenge
Full Access Account Required

Text | 5 min

Change a Password on a Remote Computer Answer
Full Access Account Required

Video | 5 min

How to Copy Files To-From a Remote Machine Challenge
Full Access Account Required

Text | 5 min

How to Copy Files To-From a Remote Machine using VSC Answer
Full Access Account Required

Video | 5 min

How to Export Logs to a CSV File Challenge
Full Access Account Required

Text | 5 min

How to Export Logs to a CSV File Answer
Full Access Account Required

Video | 5 min

How to Create Multiple Folders on the Host Machine using Powershell
Full Access Account Required

Text | 5 min

How to Create Multiple Folders on the Host Machine using Powershell Answer
Full Access Account Required

Video | 5 min

Who Rebooted the Server ID1074 Challenge
Full Access Account Required

Text | 5 min

Who Rebooted the Server
Full Access Account Required

Video | 5 min

How can you get Info on all your Hard Drives Challenge
Full Access Account Required

Text | 5 min

How can you get Info on all your Hard Drives Answer
Full Access Account Required

Video | 5 min

How can I get a list of CPU's and Installed Printers, Last Boot-up Time Challenge
Full Access Account Required

Text | 5 min

How can I get a List of CPU's and Installed Printers, Last Boot-up Time Answer
Full Access Account Required

Video | 5 min

How can I Automate Tasks with Task Scheduler Challenge
Full Access Account Required

Text | 5 min

How can I Automate Tasks with the Task Scheduler Answer
Full Access Account Required

Video | 5 min

Course Conclusion

• 1min

0 / 1 lessons complete

Writing the New-Greeting Function

Instructions

Q&A (0)

Notes (0)

Resources (1)

Saving Progress...

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

Click the dropdown below to see the full source code of the New-Greeting.ps1 file.

New-Greeting.ps1 Source Code

All right. In this lesson, we're going to be writing the functions that we'll be using for our custom module. Now, if you remember the last lecture, we created these files new greeting. ps1 and get greetingmessage. ps1. Now, you'll notice there's some placeholder text in here. You can download this. Under the resources of this lesson, it's a file called greetme-starter.Zip. This kind of includes just a description, and all of these files have some type of starter text. So does this greetme. psd1, and most usefully, they have this link to the documentation as far as, like, creating a PowerShell module manifest.

So if you want to get that, you can if you don't, that's fine. You can just look at the screen and create the functions as you see them here. But the purpose of this function is going to return a random greeting message. That's what we're going to do with this function. And the function name is going to be new dash greeting.

Okay. So I'm going to go ahead and get started and again, we want to keep this example as simple as possible. So I don't want to overwhelm you with super complicated scripts or functions. All we're going to do is create three lines of text that one of them is going to be PowerShell modules are cool, and then another one's like, I'm glad you're learning PowerShell. And then PS modules are the best. There's going to be three separate lines of code or three separate strings of greetings. And then this function is just going to return one of them at random.

Alright, so let's get started by declaring a variable called greetings, and that's going to be equal to an array, so we're going to do the at sign, open and close parenthesis, and again with Visual Studio Code, I only need to hit open parenthesis, and it'll auto close the parenthesis.

So I'll press enter, and we're going to do three strings. So I'm going to do quotation marks, so I'll hit quote two times, I'm going to hit comma, and then some Visual Studio Code magic that I like to do, I'll hit shift, alt, and the down arrow two times. And that will give me three arrays. And I'll get rid of that last comma.

Because we don't need a comma for the last entry of an array. Alright, now let's go ahead and populate this. And I'm just going to say PowerShell modules are very cool. And you're free to change these however you want. There just needs to be a certain number of strings. You can add more if you want.

But this is just kind of what I'm going to put in. So, I'm, I'm glad you are learning. Oops, spell that right, learning about PowerShell modules. And then the last one will be PS modules are the best. Okay now let's go ahead and just make comments because we want to be a good coder and if someone comes up behind us, we want them to be able to understand what our code is doing.

So select a, or declare a message greeting.

And that should be declare message greetings with an S. Okay, and now let's say get a random message, and we're going to make a variable called greeting and greeting is going to be equal to greetings, the variable we declared above, and I'm going to pipe that to get random. And if I press F8, I'm going to get an error because I haven't declared this up here.

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments