PowerShell Fast Track: Hacks for Non-Coders - podcast episode cover

PowerShell Fast Track: Hacks for Non-Coders

Jan 27, 202624 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

A practical guide for automating IT systems and processes using PowerShell. It introduces fundamental scripting concepts such as variables, conditional statements (If/Else, Switch), and loops, illustrating their application with clear examples. The material then progresses to more advanced topics including date and log management, various methods for script input (CSV, text files, user prompts, GUI), and the crucial role of PowerShell modules. The book culminates by exploring email-based alerting, robust error reporting techniques, and methods for generating diverse reports (CSV, Excel, HTML), all aimed at equipping users, even those without prior coding experience, to create efficient and reliable automation solutions.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/PowerShell-Fast-Track-Hacks-Non-Coders-ebook/dp/B0DW83MYGX?&linkCode=ll1&tag=cvthunderx-20&linkId=c738524cc3132d9126264cf31bab7455&language=en_US&ref_=as_li_ss_tl

Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

Welcome to the deep dive. Our mission cut through that information overload, help you get well informed fast ever, face those really repetitive IT tasks you know, onboarding users, maybe updating configs, running the same reports, and just think, ugh, there has to be a better way, like without needing to be some hardcore coder. Well, this deep dive is definitely for you today. We're really getting into the core insights from PowerShell Fast Track Hacks for Non Coders, second

edition by Vikasukija. Our mission is basically to give you a shortcut a way to grasp how PowerShell can genuinely simplify complex IT admin stuff even if you've never really thought of yourself as a programmer. You're going to discover some fundamental concepts yeah, but also practical real role automation and some pretty powerful cheat codes that'll save you time reduce errors big time. So okay, let's umpack this. What

is PowerShell at its core? And why is this deep dive such a potential game changer for IT pro who isn't like from a programming background.

Speaker 2

Well, what's really interesting here is how the author Vikasukija, people know him as tech wizard right over two decades in IT infrastructure. He frames PowerShell not as some super complex coding language, not at all. He calls it a task automation solution, comprising a command line shell and a scripting language, much more approachable, and the book's goal, he says, is to equip you with the skills to develop scripts through a hands on approach, so really practical for you,

the IT admin. This means you can quickly learn to write your own scripts, automate all sorts of IT systems and processes without needing that computer science degree. It's really about solving everyday problems.

Speaker 1

That's a great way to put it, not about suddenly becoming developer, but getting practical skills for IT work. Speaking to practicalities, PowerShell's evolved a lot, hasn't it. I hear it's not just Windows anymore. How big a deal is that really for IT administration today? And what's it mean if you're managing different kinds of systems?

Speaker 2

Oh, it's a huge deal. Yeah. PowerShell seven especially it brought in serious cross platform capability, so it runs smoothly on Windows, Mac Os, Linux. That's a major shift from older versions like five point one, which were well Windows only, right, and for admins. Powertell seven also means better performance, less memory usage, faster scripts. That's pretty crucial when you're automating hundreds of things or running checks all the time. Let's

you scale up without killing your systems. Now that said, PowerShell five point one is far from obsolete. Lots of scripts still use it, and most of those are compatible with powertell seven. Maybe meeting just minor tweaks okay, and running them is simple. PowerShell for five point one PFTRA version seven easy, so.

Speaker 1

You're covered whether you're on legacy stuff or the latest cloud environments. That's really key for anyone still managing older systems. Yeah, okay, so we get the big picture revolution. Let's zoom in a bit the actual building blocks for someone just starting. Where do we begin, Like just storing information?

Speaker 2

Yeah, good place to start. As variables, think of them as labeled boxes for your data. In PowerShell, they always start with a dollar sign f like that helps tell them apart from commands, and they just store stuff. Could be a number always one or textbad dollars pick gas simple, and when you want to see what's inside right host or right output, they just print it to the screen.

Right host is kind of neat you can add color like a n heavy four ground color green for you know, success messages or whatever.

Speaker 1

God, And what about storing collections like lists of things, because in it it's rarely just one server or one user exactly.

Speaker 2

That's where arrays and arraylists are indispensable. Arrays hold multiple items like servers are server one, server two, server three. But here's a really interesting point for performance, especially with like huge data sets. Traditional arrays, they're fixed size. If you add something, PowerShell actually has to create a whole new array in memory, copies everything over.

Speaker 1

Oh wow.

Speaker 2

Yeah, it can be really slow, uses a lot of resources. That's why the book suggests using arraylists as a thumb rule. Their performance rich when data set is huge because they're dynamic, they just grow as needed, much more efficient. You'd start one like this servers smong dot, collections dot a raylist at Okay, that's.

Speaker 1

A critical tip. Sounds subtle, but a massive performance difference. Definitely something to keep in mind for bigger scripts. So storing data is covered, but scripts need to make decisions right like if this condition is true, do this otherwise do that absolutely.

Speaker 2

That's exactly what conditional statements like I less are four. They let your script make choices. For instance, if a G nine checks a whyless is greater than nine? Pretty straightforward and PowerShell has a bunch of these comparison operators eq for equal mean not equal, olt less than even fancier ones like light contains to see if something's in

a list, or g match for checking text patterns. Super useful for logs, okay, and you can combine conditions too, using a or or like if or AK ten lets you build complex logic.

Speaker 1

Right. So, ifils handles those branching decisions. But what if you have one variable and it could be I don't know five or six different specific things, and you need a different action for each. Is there something cleaner than just chaining a bunch of IFEL statements together. Yeah, gets messy fast.

Speaker 2

Yeah exactly. That's the perfect use case for switch. It's much cleaner, way more readable than a long IFL sift chain when you've got one variable with multiple distinct values. Just makes your code easier to follow, easier to maintain. The basic idea is switch five's value five tag do something else default in check handle others. It just checks value against.

Speaker 1

Each case that clarifies things. Makes sense. So we can store data, check conditions. What about doing things over and over, like processing that list of one hundred users or checking one hundred servers. Copy pasting isn't going to cut it, no way.

Speaker 2

That's the whole point of loops. They're designed for executing a block of code repeatedly. PowerShell gives you a few types. Four each is really common, great for going through items in a collection, like four each user and user list.

There's also four each object, which you often use with the pipe symbol, like user list, ford object two step do something with each user processes things as they come through, and the traditional for loop exists too, though maybe less common in day to day PowerShell scripting.

Speaker 1

Okay, and while what's the difference there? Right?

Speaker 2

Wild loops two main flavors, do wile and just While do wile runs the code first, then checks the condition good if you need the action to happen at least once, like prompting for input until it's valid oh okay, whereas while checks the condition before running the code perfect if you only want to proceed if the condition is met right at the start.

Speaker 1

Makes sense, especially that do wild distinction guarantees it runs once. So loops handle repetition. But what if you have a chunk of code you use all the time in different places, maybe even different scripts. Copy pasting seems risky, errors creep in.

Speaker 2

Yeah, you've hit on something crucial for writing maintainable code. Functions. Functions are basically reusable blocks of code that you define once and can call from anywhere in your script. They cut down redundancy massively, make your code way more organized, easier to debug. Two like a simple AD function function AD eight dollars D dollars plus B dollars. Then you just call AD five to six whenever you need it.

Speaker 1

So, putting it all together, what does this mean for someone just wanting to automate stuff? It really sounds like PowerShell gives you the essential tools, you know, without needing a whole computer science background.

Speaker 2

That's precisely it. These foundational bits, variables, arrays, conditions, loops, functions, they're absolutely crucial. They let you build robust, effective scripts for real production environments. They're the building blocks. Once you get these, you can really start automating your work.

Speaker 1

Okay, building on those basics, let's get practical. Because scripts aren't just about doing a task right. They need to be smart track things take input in different ways. For admins, logging and auditing often just as important as the automation itself.

Speaker 2

Couldn't agree more. One of the first practical things for any script is handling dates and logs. Timestamps are vital tracking operations, creating unique filenames, building those audit trails. Get date gives you the current data and time easily, and you can format it however you need IILCHA, mmddxcmd, SDS whatever. Then you can, like the book says, glue them all together for unique log names like skipsees be eighteen, ASU eight twenty twenty five, thirty three five five dot log.

It's also great for more complex stuff like getting the first or last day of the month for reports, or maybe a midnight timestamp for daily summaries.

Speaker 1

Super practical. I can totally see using that to create dated folders like can fig back up twenty two five zero eight when you know exactly when that.

Speaker 2

Backup runs exactly, And the book even provides some ready made functions cheat codes basically to make this easier. There's right log automatically creates timestamp logs even lets you specify severity information warning error makes logs structured and critically set recycle logs. This automatically deletes old log files based on age, say older than thirty days, Super important to avoid filling up server drives. Right works locally remotely specific paths, very flexible.

Oh and there's even start progress bar for giving some visual feedback while long scripts run, so you're.

Speaker 1

Not just automating the job, but the cleanup too. That's a huge time saver. What about getting data into the scripts? Admins are always dealing with lists, users from HR server lists, guys can figs from spreadsheets.

Speaker 2

Yeah, handling input to your scripts is absolutely essential for real world stuff. Probably the most common method for providing a script with structured input data is import CSV. Perfect for bulk operations. Think updating hundreds of user accounts, migrating mailboxes. You import a CSV file, maybe with columns like user email title. Then you loop through accessing data like I dot user or I email connects directly to things like

updating active directory, user attributes, city, state, job title. All that and you can weave right log right into that process. Log Each updates successful or not, leaves a clear audit trail.

Speaker 1

So it's not just fire and forget you know exactly what happened precisely.

Speaker 2

Now. For simpler lists, maybe just a text file with server names one per line, use get content and you typically loop through that using for each object. Or hey, sometimes the data might just be an array you define right in the script, like servers at server zero one, server zero two. If it's a short list, and what if you need.

Speaker 1

The script to ask the user something all t running which server? Or are you sure bad? That kind of thing?

Speaker 2

Interactive input read host is your friend.

Speaker 1

There.

Speaker 2

It prompts the user and waits for their input. It gets really powerful with a secure string. Use that to securely tap your passwords or other sensitive info. It encrypts the input immediately, so it's never stored or logged as plaintext. Absolutely vital for things like Office three sixty five logins or apikes. What you get back is a PS credential object that's PowerShell's secure way to handle those credentials within the script.

Speaker 1

This really makes scripts feel more intelligent. We're moving beyond just simple commands to something that gathers info, logs progress, even cleans up.

Speaker 2

Indeed, these methods let you build scripts that are not just powerful, but also robust auditible, user friendly. They handle data the way you actually encounter it in day to day It work. It's about building real solutions.

Speaker 1

Okay, moving beyond just text input, what about more interactive ways, maybe even graphical? And then let's tackle something huge modules. How can we make scripts even more user friendly, say for someone who isn't super technical?

Speaker 2

Well, for more interactive input, the book actually shares a neat cheat code function. Let's you create a simple GUI button. Now it's probably less common for pure server automation, but it creates a basic Windows form, you know, textboxes and ok. Button makes scripts feel more engaging, maybe more intuitive for users who prefer clicking over typing. The values they enter get passed back to your script in an array like return dollars. Interesting, and another really useful interactive bit is

a simple yes no prompt. You can use a wscript dot shell pop up crucial for getting confirmation before doing something critical like do you want to overwrite ad attributes? Stops accidents, essential safety check.

Speaker 1

That's a handy trick, especially for scripts running locally. Okay, now let's talk modules. The book calls them the batteries of power show. What are they exactly and why are they so important for modern automation? Right?

Speaker 2

Modules? Think of them as a package that contains PowerShell members, fnmellets, functions, variables all bundle together. They're not just code packages, though, they're really essential for interacting with a wide range of products and services. We're talking Azure Office three sixty five,

Exchange Online, Teams, Serpoint Online, even aws everything. So you're not just automating local stuff, You're orchestrating big, enterprise wide workflows using tools built specifically for those platforms.

Speaker 1

That really frames their importance. So where do you find these batteries and how do you plug them in?

Speaker 2

The main hub is the PowerShell Gallery at www dot PowerShell gallery dot com. It's the central repository for almost all public modules. Installing is usually simple, install module, dash name, Azure aid for example. You can update them too, update module or install module names. Some module forced to overwrite an existing version and remove module gets rid of them.

Since PowerShell v three modules often load automatically when you try to use one of their commands, pretty slick, but import module still works if you need to load one explicitly. Oh in just a quick note, snappins. That's the legacy approach Older stuff like Exchange two thousand and seven, two thousand sen maybe quest eight tools modules are the way forward.

Speaker 1

Got it? And speaking of specific modules, the AUSO has his own right the v sadmin cheap module. What's special about that one? Ah?

Speaker 2

Yes, the v sadmin module. It's a really powerful resource Visus built himself, packed with functions to streamline common, often tricky admin tasks. Like it has converts CSV to Excel huge benefit. Converts CSV to a proper Excel file without needing Excel installed on the server. That's amazing for automation wow, Or get AD group members Recursive gets all members of an AD group, even if they're nested deep inside other groups.

Saves a ton of manual effort. Then there's get off and save encrypted password crucial for handling credentials securely saving them to ENCRYPTI files or getting ps credential objects for PowerShell commands.

Speaker 1

That secure credential handling sounds vital. Where are cloud stuff like connecting to Microsoft three sixty five That could be fiddley sometimes.

Speaker 2

Absolutely The launch and remove functions are great for that, like launchioll for Exchange Online, launch SPO for SharePoint Online. They simplify the whole connection and disconnection process. And importantly they support using a client ID and certificate for app authentication. That's the modern secure way for scripts to connect without needing usernames and passwords stored anywhere.

Speaker 1

Much better, definitely.

Speaker 2

The module also helps with hybrid environments by encouraging command prefixes like get EO mailbox versus get mailbox so you know which environment you're targeting, avoids confusion. Plus little helpers like new random password for generating complex passwords right there in your script.

Speaker 1

This is fantastic stuff. So you can make scripts interactive, tap into this huge library of modules for different systems and even use custom ones like vsadmin for specific shortcuts. Really expands what's possible, right.

Speaker 2

And it brings up a good point in this world of just information everywhere, how do you manage your own automation effectively? Modules are key. They give you the tools for specific platforms, and things like visadmin are designed to really simplify those common everyday admin headaches.

Speaker 1

Okay, we've got our toolkit built. Let's talk about making scripts truly production ready error reporting and well just reporting in general, because a silent failure that can be worse than no script at all.

Speaker 2

You absolutely nailed it. Error reporting is a non negotiable they must have you need to know if something breaks. PowerShell has a built in variable error It holds all the errors from your current session. You can grab the most recent error eer dollars and email at using tenmail message, or the sabin module has a send email function that's

better at handling the whole error array. If you want more context and super important, remember error dot clear at the start of your script, Otherwise you might send old, irrelevant errors for a complete play by play. Start transcript and stop transcript are fantastic. They log everything output commands, entered errors to a text file, great for debugging or auditing, and you can also explicitly log errors using that write log function we mentioned setting the severity to error.

Speaker 1

Okay, so we can log comprehensively and get notified. But what about making the script itself tougher so it doesn't just fall over when it hits a snag.

Speaker 2

That's where tricatch blocks are essential. They provide a more structured way to handle exception errors. Basically, you put the code that might fail inside the triblock. If an error occurs, the catch block runs instead of the script crashing. Inside the catch, you can log the specific error, send an email notification, maybe try an alternative action, or just exit gracefully. It makes your scripts much more robust, much more reliable for production use.

Speaker 1

Okay, that makes scripts resilient. Now, once it has run successful or not, you often need to present the results, maybe to management, maybe just for your own records. That's where good reporting comes in.

Speaker 2

Absolutely reports are essential tools. Presenting data clearly helps stakeholders understand what's happening, helps improve processes. Export CSV is probably the workhorse here, a powerful and flexible tool for getting data into spreadsheets. Exporting mailbox details, name, email address, quota from Exchange simple effective right. For more complex CSV reports, you might need to pull data from multiple places, maybe get user info from ad than mailbox stats from Exchange.

Based on a list of users, you'd fetch the data from each source, combine it into a custom object in PowerShell, and then export that combined object to CSV.

Speaker 1

And what about those tricky fields that have multiple values, like recipients on an email log? How does CSV handle that?

Speaker 2

Good question? For multi valued attributes, export CSV lets you use custom expressions. You can join all the values into a single string, maybe separated by commas or semicolons like aud at name recipients, expression at of recipients next join makes the CSV readable clever.

Speaker 1

Okay, CSV is great, but sometimes you need something nicer looking like Excel or even HTL for a dashboard.

Speaker 2

Yeah, for Excel reporting it often looks more polished and user friendly, especially for management charts formatting. All that. Method one is using a cheap function like save cs V to Excel from vsadman. But remember that usually needs Excel actually installed where the script runs.

Speaker 1

Ah.

Speaker 2

Okay, limitation there, which brings us to method two, the import Excel module. This thing is seriously powerful, probably the most popular and powerful PowerShell module for Excel work. Key advantage it lets you create and manipulate real Excel files without needing Excel installed. Huge for server automation. Cannot stress that enough.

Speaker 1

That is a game changer. Wow, and HTML.

Speaker 2

Hmail reporting is great for visual dashboards. Think traffic light indicators showing service status read for down, green for up. Easily viewable in a browser. You can even use online HTML editors like HTML dash online dot com editor to design your table or layout. Then grab the HTML code and embed it right into your PowerShell script to populate with live data. The Exchange health check example uses this.

Speaker 1

This is truly getting to power user level building in safety nets, robust error handling, and then presenting results professionally. That knowledge is invaluable.

Speaker 2

It really is. Knowledge is great, but it's most valuable when understood and applied right. These techniques ensure errors get logged, reported, handled properly, and that your data gets presented clearly. Leads to more reliable systems, better decisions. Transforms a simple script into a proper solution.

Speaker 1

We've covered so much basics, data handling, security, error handley, reporting, shoe. Now let's get into some advanced hacks, cool ways to manipulate data, and then, crucially, how do we glue all these pieces together solve those real world problems right?

Speaker 2

Some miscellaneous keywords that are data manipulation masters, split super useful breaks a string into pieces based on a character, like splitting an email first dot last at domain dot com on the dat and at to get first name, last name domain. Replace does what it says, substitutes text. Maybe replace dot wit in that email address if you need it. For a file name selects string. This is

like rep for powersheld people searches for text patterns inside files. Example, get child items, CE data logs, select string to pattern r instantly finds all lines containing error in your logs. Massive time saver for troubleshooting.

Speaker 1

Definitely faster than opening each file. What about compare object sounds powerful?

Speaker 2

Oh it is? Compare object is highly efficient for comparing two sets of data files or raise whatever. Perfect for comparing AD group memberships. Find who's in group A but not group B or vice versa. Let's you synchronize groups, add the missing or remove the extras ensure they match perfectly. Also great for emerging CSV files based on a common field, like matching up user details with their OneDrive usage sets.

Speaker 1

This is absolutely the aha moment. We've seen all these tools, variables, loops, modules, error handling, reporting, and now you're showing how they connect, how they solve actual common IT problems. Takes it from theory to real.

Speaker 2

Results exactly, and there's always more to learn. But seeing how the pieces fit that lets you build really sophisticated, efficient solutions for your daily work. Let's walk through that scenario again, adding users from an HR file to an AD group for say fileshare access your scripts. Would you know, maybe add some headers for clarity, import the modules needed, visadmin active directory, define your variables, dot log file path, the user list file, the AD group name. Maybe how

many old logs to keep. Then the main loop go through each user in the list, check if they're already in the group using get ady user member of If not, add them with AD eighty group member, and critically sprinkle writ log calls throughout log who's being processed, who's added, any errors encountered, and at the end set recyclogues to

clean up those old log files automatically. See that one example pulls together variables, file input loops, eighty commands, logging, clean up almost everything we've discussed.

Speaker 1

It really crystallizes it, and it shows powershells adaptability. Right, It's not just for one thing. The joy is seeing these tools apply everywhere.

Speaker 2

That adaptability is its core strength. It's used everywhere with Microsoft Exchange, cleaning databases, finding orphan mailboxes, tracking messages, reporting quotas, setting quotas you name it, active directory, exporting group members, recursively, setting attributes from CSPs, exporting attributes to Excel, adding removing users from files, native ad modules, quest modules, Office three sixty five detailed exchange online reports, message tracking in the cloud, searching,

the unified audit log for teams, activity exchange changes, and.

Speaker 1

Beyond the Microsoft stack too.

Speaker 2

Oh yeah, AZUREAD or Entra as it's called now, adding removing users from cloud groups, checking memberships, assigning admin roles, checking provisioning, sink errors, and a really key thing here the Microsoft Graph module. The old AZURID and MSOL modules, they're on their way out. Microsoft Graph is the unified API, the future one way to manage Azure Office three sixty five teams, SharePoint, tons more, definitely the way to go

for future proofing scripts. Good to know even AWS. The AWS PowerShell module lets you manage AWS resources like get a two instants to list your virtual servers, plus all the general tech CSV file operations, quick tricks for headers, data cleaning, and don't forget rejx regular express, super powerful for matching complex text patterns, validating emails, pulling specific data from messilog files. Huge potential. There.

Speaker 1

What a comprehensive tour from PowerShell basics right through to advanced data slicing, secure connections, error handling, reporting across just about every major IT platform. This deep dive has seriously armed you, the listener, with insights and tools to really streamline your IT work.

Speaker 2

Yes, absolutely, and this knowledge means you can take those repetitive, time consuming tasks and automate them, improve efficiency and sure things are done consistently. Makes you a more effective, more valuable IT pro even if you know you didn't start out as a coder. It's about using the right tool for the job.

Speaker 1

We really encourage you to try some of these cheat codes out, explore those ready made scripts maybe at tech wizard, dot cloud, downloads like the book mentions, and just to leave you with a final thought to chew on, given how much time automation can save, what's one small, maybe seemingly insignificant, repetitive task in your own digital life or workflow that you could maybe start automating today, And how I might tackling just that one small thing ripple out

and save you hours, maybe even days over the next year. Something to think about.

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android