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

Reading input from the host

Admittedly, reading input given by the user at the host is not among the best things for automation. However, in some situations, it is necessary. Let's not leave such stones unturned, at least. In this recipe, we will ask the user for their name, and then display the greeting along with the date. Optionally, you can have a space in the name of the script.

How to do it...

This is straightforward. If you are comfortable using command discovery, you can simply use get-command *host to get the information. Modify the script we created for the Writing a simple script recipe to get the desired script:

Get-Date

hostname

Write-Output "Hello, $(Read-Host "Enter your name")!"
...
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 $19.99/month. Cancel anytime