My PowerShell Scripts - Systems Administration #powershell #script #sysadmin

PC-Addicts
24 Jan 201304:36

Summary

TLDRIn this informative video, the speaker discusses the utility of a custom PowerShell module they've created for work. They've consolidated multiple scripts into one, which can be used by changing the file extension from .PS1 to .PSM1. The module contains individual functions that can be imported into a PowerShell profile for easy access. The speaker highlights several functions, including a ping utility, a function to retrieve the currently logged-in user on a remote computer, a function to check system uptime, and a tool to examine installed drivers and their installation dates. They mention that these scripts will be shared on their website, PCXCOM, and encourage feedback for improvement.

Takeaways

  • 📚 The speaker has combined multiple useful scripts into a single module for convenience at work.
  • 🔄 To use the module, one must change the file extension from .PS1 to .PSM1.
  • 📝 The module contains individual functions that can be imported into the shell for frequent use.
  • 💡 One function mentioned is a quick ping script, which can be invoked by typing 'P' followed by a domain name.
  • 🖥️ The 'Get-LoggedIn' function is highlighted as the speaker's most frequently used script, which retrieves the currently logged-in user on a local or remote computer.
  • 👥 The 'Get-LoggedIn' function can handle multiple computer names at once, separated by commas.
  • ⏱️ The 'Get-UpTime' function is used to check how long a computer has been running, which is helpful for verifying system restarts.
  • 🛠️ Another script provided by a system admin helps to check installed drivers and their installation dates for specific hardware.
  • 🔍 The hardware script can be filtered to show only drivers related to a certain name, such as 'Intel'.
  • 🔗 The speaker plans to make these scripts available on a website, with a link expected to be provided in the video description.
  • 🗣️ The speaker invites feedback and suggestions for improving the module or adding new tips and scripts.

Q & A

  • What did the speaker do with the scripts they use at work?

    -The speaker combined several useful scripts into one script, saved it as a module, and changed the file extension from .PS1 to .PSM1.

  • How does one use the module created by the speaker in their PowerShell environment?

    -To use the module, one needs to import it in their PowerShell profile script.

  • What is the purpose of the 'P' function mentioned in the script?

    -The 'P' function is a quick ping script that the speaker occasionally uses, although they find typing 'ping' directly quicker due to familiarity.

  • How can the 'Get-LoggedIn' function help in a work environment with many computers?

    -The 'Get-LoggedIn' function retrieves the user currently logged into a specified computer, which is useful for quickly identifying who is logged into a computer, especially in an environment with thousands of computers.

  • What does the 'Get-UpTime' function do and why is it useful?

    -The 'Get-UpTime' function shows how long a computer has been up and running, which is helpful for verifying system restarts and uptime.

  • How can the 'Get-Hardware' function assist in managing drivers on multiple computers?

    -The 'Get-Hardware' function allows users to check what drivers are installed on a computer and when they were installed, aiding in driver management and troubleshooting.

  • What is the benefit of having individual functions within a module?

    -Having individual functions within a module allows for modularity and reusability, making it easier to manage and maintain the code, as well as to use specific functions as needed.

  • How can the speaker's scripts be accessed by those interested?

    -The scripts will be made available on the speaker's website, PCXCOM, with a link provided in the video description on the YouTube page.

  • What does the speaker suggest if someone has tips or suggestions for improving the scripts?

    -The speaker encourages viewers to share their tips or suggestions for improving the scripts or adding features to the module.

  • What is the significance of changing the file extension from .PS1 to .PSM1 in PowerShell?

    -Changing the file extension from .PS1 to .PSM1 signifies that the script is being used as a module in PowerShell, allowing for easier import and use of the script's functions.

  • How does the speaker organize their frequently used functions?

    -The speaker organizes their frequently used functions in a storage area or script, making them available within the shell every time it launches.

Outlines

00:00

🛠️ PowerShell Script Module for IT Efficiency

The speaker discusses creating a PowerShell script module that consolidates multiple scripts into one for increased efficiency at work. The module is saved with a .psm1 extension and includes individual functions. The speaker mentions that a simple 'ping' script is included, which they don't use often but find neat. The 'get-loggedIn' function is highlighted as the most frequently used, allowing the user to quickly determine who is logged into a local or remote computer. The 'get-upTime' function is also mentioned, which provides information on how long a computer has been running. Lastly, a function provided by a system admin is described, which helps to check installed drivers and their installation dates for specific hardware. The speaker intends to make these scripts available on a website for others to use and encourages feedback for improvement.

Mindmap

Keywords

💡Scripts

Scripts in the context of the video refer to a series of commands or programs written to automate tasks in a computing environment. They are essential for the video's theme as they are the primary tools discussed for enhancing productivity at work. The script mentioned is combined into one module, which is a collection of functions that the user finds handy.

💡Module

A module in the video is a single file that contains multiple scripts or functions, which can be reused across different projects or tasks. The concept of a module is central to the video's theme of streamlining work processes. The user saves their combined scripts as a '.psm1' file, which is a PowerShell module file, to be imported and used in their shell environment.

💡File Extension

File extensions in the video are used to denote the type of file and its associated program. Changing the file extension from '.ps1' to '.psm1' is a key step in converting a script file into a module, as mentioned in the script. This is a practical example of how file extensions are used to manage and organize files in computing.

💡Import

Importing, in the context of the video, refers to the action of bringing a module into the current session of a shell or script environment. This allows the user to access the functions within the module without having to rewrite or copy them each time. It's a fundamental concept in the video that enables the use of the combined scripts.

💡Functions

Functions in the video are individual units of code within a script or module that perform specific tasks. They are the building blocks of the module discussed in the video and are used to create reusable code for various automation tasks. The script contains several functions like 'Get-LoggedIn' and 'Get-UpTime', which are explained with examples of their usage.

💡Ping Script

A ping script, as mentioned in the video, is a simple function used to test the connectivity between two networked devices by sending ICMP echo request messages. Although the user admits to not using it often, it's included in the module as an example of a handy function that can be quickly accessed.

💡Get-LoggedIn

Get-LoggedIn is a specific function within the module that retrieves the user currently logged into a remote computer. It's highlighted in the video as the user's most frequently used function, demonstrating its practicality in a work environment where managing multiple computers is common.

💡Get-UpTime

Get-UpTime is another function in the module that the user discusses. It is used to determine how long a computer has been running or 'up'. This function is valuable for verifying system restarts and ensuring that computers are up-to-date, which is a common task in IT support roles.

💡Hardware Version

Hardware version in the video refers to a function that checks the installed drivers and their details for a particular piece of hardware. It's a useful tool for system administrators to manage and track driver updates across multiple devices, as illustrated by the user's example of filtering for 'Intel' related hardware.

💡PCXCOM

PCXCOM appears to be a website or platform where the user intends to make the discussed scripts available. It is mentioned in the context of sharing resources, which aligns with the video's theme of enhancing work efficiency through shared scripting solutions.

Highlights

The speaker consolidated multiple useful work scripts into one module.

To use the module, change the file extension from .PS1 to .PSM1.

Import the module in the PowerShell profile to have it available at every shell launch.

The module consists of individual functions stored in a 'storage area'.

A quick ping script is included, which can be invoked by typing 'P'.

The ping script returns 'true' if the host is reachable, otherwise 'false'.

A function named 'get-loggedIn' retrieves the user currently logged into a remote computer.

Tab completion is supported for ease of use within the 'get-loggedIn' function.

The function can handle multiple computer names for checking logged-in users.

A 'get-upTime' function is used to check how long a computer has been running.

The 'get-upTime' function provides information in days, hours, and minutes.

A script to check installed drivers and their installation dates is included.

The hardware information script can filter results by name, such as 'Intel'.

The speaker plans to make these scripts available on the PCXCOM website.

A link to the scripts will be provided in the video description on the YouTube page.

The speaker invites feedback and suggestions to improve the module and scripts.

Transcripts

play00:00

there's a few scripts that I use at work

play00:02

that come in very handy and what I did

play00:04

is I actually bumped them into one

play00:06

script and saved it as a module and the

play00:11

only thing you have to do is change the

play00:14

file extension from PS 1 to PS m 1 to

play00:17

make it a module and then what I do is

play00:18

in my pull file I just import this

play00:22

module and so let's go ahead and take a

play00:24

look at what's in this module now you'll

play00:28

notice they're individual functions and

play00:31

that's all you got to do is create

play00:32

individual functions and this is kind of

play00:35

just like my storage script or storage

play00:37

area where I store all these functions

play00:39

that I I use frequently and that I want

play00:42

to have available within the shell every

play00:45

time it launches the first one now this

play00:47

one I'll be honest with you I don't use

play00:49

it much but I did I saw it on I don't

play00:52

remember whose blog it was but maybe was

play00:55

Don Jones or something but I thought it

play00:57

was pretty neat and I do find myself

play00:58

using it every once in a while and all

play01:00

it is is a quick little ping script now

play01:04

to me it's kind of quicker just to type

play01:06

ping because I'm so used to it but you

play01:08

know it's kind of neat to to see it and

play01:10

but you know what I don't think I have

play01:12

this function and I just named it the

play01:14

letter P I don't think I have this I

play01:16

don't have I don't think I've imported

play01:18

this module yet so let's test it if I

play01:21

just do P and then google.com well it

play01:24

does work so I do have it imported so

play01:26

disregard so it's just basically saying

play01:30

true it's paintable now if we try to

play01:32

paint something else it's false so

play01:36

that's all that one does now the next

play01:39

one here this one I use all the time at

play01:42

work this is probably my number one

play01:43

script that I use or a function that I

play01:46

use I just called it get logged in and

play01:48

all it does basically is gets or

play01:52

retrieves the user that's currently

play01:54

logged into the remote computer now I

play01:57

don't have a remote computer here to

play01:58

test with but I can just do it on this

play02:00

local machine so if we do get - logged

play02:04

in and tab completion works and I'm just

play02:07

gonna put in localhost here's where you

play02:09

would just normally put in the remote

play02:10

computer name hit enter and it says

play02:13

the computer name and who's logged into

play02:15

it now for instance we want to do

play02:16

multiple computers at once all you gotta

play02:18

do is put a comma

play02:19

I'll just put one and it'll just go down

play02:23

the list I find this very useful

play02:25

especially at work where we have

play02:27

thousands of computers and different

play02:30

users and I just need to see who's

play02:31

logged into a computer really quick so

play02:34

the next one is getup time now I do use

play02:37

this one quite frequently too you know I

play02:39

have some users ask him have you have

play02:40

you restarted computer and they'll say

play02:42

yeah and then I'll double check it real

play02:43

quick and they turns out they haven't

play02:45

this one just goes and lets you know how

play02:49

long the computer's been up so it's

play02:51

clear this if we do get - uptime and

play02:55

then you can put in your computer name

play02:56

for instance here we'll just do

play02:58

localhost tells you how many days the

play03:01

computer name eight seconds the minutes

play03:03

and hours that one comes in pretty handy

play03:06

- and this last one it's provided via

play03:11

one of the system admins at work I'm not

play03:14

sure if he wrote it or or I got it

play03:16

somewhere or whatnot but this one comes

play03:17

in handy if you want to check like what

play03:19

drivers are installed and maybe when the

play03:21

drivers were installed for a particular

play03:23

piece of hardware now if you just run it

play03:24

by itself without a parameter so let's

play03:27

just do get hardware version it's built

play03:31

nope we need a computer name on this one

play03:34

so we're just gonna do localhost

play03:36

so that's gonna go through grab all the

play03:40

information about all the hardware and

play03:42

you know that's a lot of reading and all

play03:44

this stuff but let's just break it down

play03:45

to let's say we just want stuff that's

play03:47

related to the name or that contains the

play03:49

name Intel for like the NIC card or

play03:52

something or the CPU so here you can see

play03:56

we got a gigabit network card the driver

play03:59

date was 229 2012 and the driver version

play04:03

so this comes in handy if you're trying

play04:05

to figure out what computers have what

play04:07

versions of what driver and when they

play04:09

were installed and all that stuff so

play04:10

this one this one comes in pretty pretty

play04:13

handy now all these scripts are going to

play04:15

be available I'm gonna make them

play04:16

available on the site so check out PC

play04:18

XCOM and there should be a link in the

play04:20

description under this video on the

play04:22

YouTube page so alright guys hopefully

play04:24

you found this helpful and if you have

play04:26

any

play04:26

tips for you know what you would like to

play04:29

see in this kind of a module or tips to

play04:32

make these scripts better please don't

play04:34

hesitate to let us know

Rate This

5.0 / 5 (0 votes)

相关标签
PowerShellScriptingIT AutomationSystem AdminModule CreationRemote AccessUser ManagementDriver CheckUptime MonitorTech Tips
您是否需要英文摘要?