Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PowerShell Core for Linux Administrators Cookbook

You're reading from   PowerShell Core for Linux Administrators Cookbook Use PowerShell Core 6.x on Linux to automate complex, repetitive, and time-consuming tasks

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789137231
Length 566 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Ram Iyer Ram Iyer
Author Profile Icon Ram Iyer
Ram Iyer
Prashanth Jayaram Prashanth Jayaram
Author Profile Icon Prashanth Jayaram
Prashanth Jayaram
Arrow right icon
View More author details
Toc

Table of Contents (19) Chapters Close

Preface 1. Introducing PowerShell Core 2. Preparing for Administration Using PowerShell FREE CHAPTER 3. First Steps in Administration Using PowerShell 4. Passing Data through the Pipeline 5. Using Variables and Objects 6. Working with Strings 7. Flow Control Using Branches and Loops 8. Performing Calculations 9. Using Arrays and Hashtables 10. Handling Files and Directories 11. Building Scripts and Functions 12. Advanced Concepts of Functions 13. Debugging and Error Handling 14. Enterprise Administration Using PowerShell 15. PowerShell and Cloud Operations 16. Using PowerShell for SQL Database Management 17. Using PowerShell with Docker 18. Other Books You May Enjoy

Handling dependencies and prerequisites

A function, in fact, is made of three blocks, apart from the param() block. These are begin, process, and end.

By default, whatever you specify after the param() block will be treated as belonging to process, unless you specify otherwise.

Create a wrapper function to create three files, test1.txt, test2.txt, and test3.txt. However, before creating the files, output the date. You must be able to call the function like so:

PS> New-File 'test1.txt', 'test2.txt', 'test3.txt'

How to do it...

The logic is simple. We will use a begin block to show the date, and have the file creation part in the process block. The process block will have a looping construct...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime