Leanpub Header

Skip to main content

PowerShell to C# and back

A journey to C# and becoming better at PowerShell

Learn C# and PowerShell together and excel at both!

Minimum price

$24.99

$29.99

You pay

$29.99

Authors earn

$23.99
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
177
Readers
168
Pages
24,244Words
About

About

About the Book

Why did we write this book?

We started writing this book to document our journey to learn C#, to be honest, we were scratching our own itch. There is no book or tutorial available today that can bridge the gap between a scripting language like PowerShell and modern programming language like C#, which is a natural language of choice, so we decided to write our own!

This book is the second book of this type since Prateek has written "PowerShell Guide to Python" a year back to take readers on a journey to learn Python using Powershell with the benefits of associative learning. Back then the most popular request\feedback was a book to cover PowerShell and C# together, so here it is! :)

PowerShell cmdlets are mostly written in C# and very often you will see .Net classes utilized in PowerShell scripts, and it seems like both these worlds are very much interconnected but still, there is a lot of friction, especially for IT professionals who lack understanding of object-oriented programming and find it difficult to understand software design patterns.

The purpose of this book is to provide bite-sized easily consumable chunks of knowledge and concepts to the reader, that will make it simple for them to learn and understand C# and improve their skill sets. More than that, leaving readers will tip, tricks and scenarios, that will develop a synergy with C# and PowerShell, and the knowledge attained can be refed further extend their capabilities by writing better and advanced scripts and Automation.

"Your problem is to bridge the gap which exists between where you are now and the goal you intend to reach."
                  ~ Earl Nightingale

Who is the Target Audience?

C# can be used to create almost anything from Windows desktop applications and games to develop powerful web applications and has become increasingly popular for mobile development too. Cross-platform tools such as Xamarin allow apps written in C# to be used on almost any mobile device. On top of that, since the announcement of .NET Core which is an open-source, general-purpose development platform now you can create .NET Core applications using C# for Windows, macOS, and Linux this just opens up a lot of opportunities and horizons for C#.

System Administrators and IT Professionals

System Administrators who want to upgrade their PowerShell scripting skills into C# Development or Programming roles, this book is written exactly keeping you in mind. The purpose of this book is to bridge the gap between PowerShell and C# and leave the readers with enough confidence, exposure, and hands-on experience so that they can develop in C# comfortably. Microsoft's cloud platform 'Azure' is growing rapidly, and having C# and PowerShell in your skill arsenal, that compliment each other and align with Azure automation and development needs, will definitely give you a competitive advantage as an IT professional.

C# Developer

If you are a C# developer and want to learn to write powerful automation and scripts using PowerShell, then you must read this book, because this book will help you associate concepts of modern programming language like C# with PowerShell and make it easy for you to learn PowerShell. Nowadays most of the CI/CD platforms like Azure DevOps leverage some sort of scripting language to run tasks and background jobs in their pipelines, so learning PowerShell will start to impact your day job in a good way.

What to expect from the Book?

Each chapter begins with a set of learning goals for the chapter and the topics covered as a list, which gives a fair idea to the reader what to expect in the chapter. It also enables the readers with a choice to skip the chapter if the topic is familiar and can be revisited later stage. After this a small introduction of the chapter to make the reader comfortable with the topic, followed by the main content of the chapter, headings, and sub-headings, figures, code samples/examples.

Towards the end of the book, all chapters have a 'Key takeaway' section which summarizes key pointers of the chapter. Key takeaways can be used to reinforce the learning and even come handy during revisions without going deep dive into the whole chapter again. Finally, chapters will end with some Exercises\Assignments that will further allow you to use the learnings from the chapter and implement that in code.

All chapters end with some reading recommendations, the official documentation for the reader on the related topic, which readers can follow to gain knowledge on the topic which is out of the scope of the book. Following is the structural pattern you will observe in all the chapters:

  • Purpose of the chapter
  • Introduction to the chapter
  • Main chapter content
  • Key Takeaways from the Chapter
  • Exercises and Assignments
  • Reading Recommendations

Available Book Formats

The book can be download in any of the following formats and it is recommended to read it on a personal computer in PDF format for clarity in images and code samples. We might publish this book on Amazon through Kindle Direct Publishing (KDP) in digital post-completion and even print it in the future but for now, it is only digitally available here.

  • PDF - For laptops and personal computers
  • EPUB - For phones and tablets
  • MOBI -For Amazon Kindle and E-Readers
  • WEB - On the web browser

Book updates and email notifications

This book has been published as we are writing it, a chapter at a time on Leanpub.com , which is a lean publishing platform and we will keep on updating and improving the book so that you have the best version of the book available. This book is work in progress and it is recommended that you allow Leanpub to send you update emails when a new version of the book manuscript is published. 

By default, this setting is not enabled and you have to turn it on by following the below steps, otherwise, you will miss any new chapters or updates we push to the book.

  1. Log into your Leanpub.com account
  2. From the top-right corner in the 'Account' drop-down menu, click on 'Library'
  3. Click on this book in your library.
  4. Now on the right-hand side, you will get 'Email Settings'
  5. Under 'Email Settings' select the checkbox next to 'New version available'

How to Provide Feedback?

We would appreciate you sending us an e-mail to prateek@ridicurious.com with any feedback about how you are using the content, and how the book could be improved, but this is just a request so that we can improve the book and track how it is being used. You can also use the "Email the Author(s)" option on the book webpage to reach out to both of us!

Share this book

Author

About the Authors

Prateek Singh

Prateek Singh is an Infrastructure Developer, an avid PowerShell blogger, and a community contributor. In 2017 and 2018, FeedSpot and SQLHack recognized his blog RidiCurious.com as among the “Top 50 PowerShell blogs in the world.” Find his open-sourced at GitHub, and reach out to him on Twitter at @singhprateik.

Prateek has written more than 250 articles on his blog and several other websites such as 4SysOps.com, IPSwitch.com, and TechTarget.com and also runs a YouTube channel. He is a published author of 3 books and contributing author of 2 Book and currently writing the 6th one, following is the complete list:

Deepak Singh Dhami

Deepak works as a systems engineer touching cloud platforms, build/release & automation. Awarded Microsoft Most Valuable Professional award (year 2014-17) for his contributions in the Cloud & Data-center Management.

Recently, he has started going back to his development roots and picking up C#, Go for Infrastructure development needs.

Blog - https://dexterposh.github.io/

GitHub - https://github.com/DexterPOSH

Reach out to him on Twitter @DexterPOSH

Contents

Table of Contents

About the Book

  1. Why did we write this book
  2. Who is the Target Audience
  3. System Administrators and IT Professionals
  4. C# Developer
  5. Book updates and email notifications
  6. How to provide Feedback

Prerequisites

  1. Setup and Tools
  2. Windows PowerShell
  3. PowerShell Core
  4. Visual Studio Code, C# and Extension .Net Core SDK
  5. Visual Studio (Optional)

How to Use this Book

  1. Available Book Formats
  2. Structure of a Chapter
  3. Downloading Code samples and Examples
  4. Running code samples and examples
  5. C# Interactive Window in Visual Studio
  6. dotnet-script extension for .Net Core Command Line
  7. PowerShell and C# Jupyter Notebooks

Chapter 1: C# Primer

  1. Purpose of the Chapter
  2. Introduction
  3. C# Language
  4. Key Characteristics
  5. A Brief History of CSharp
  6. Compilers, Runtime and .NET Framework
  7. Program Structure and Organization
  8. Program, Assemblies and Hello World
  9. Namespaces
  10. Class
  11. Members
  12. C# Programming Elements
  13. Comments
  14. Case Sensitivity
  15. Using Directive and Statement
  16. Types and Variables
  17. Values Types
  18. Reference Types
  19. Variables
  20. Operators, Operands and Expressions
  21. Operators
  22. Basic Input and Output
  23. Conditional statements
  24. If and If..Else statement
  25. Switch statement
  26. Loops and Iterations
  27. Exceptions Try..Catch..Finally
  28. Classes and objects
  29. Arrays
  30. Summary
  31. Key Pointers
  32. Exercises and Assignments
  33. Reading Recommendations

Chapter 2: Classes and Objects

  1. Purpose of the Chapter
  2. Introduction
  3. Procedural vs Object-oriented programming
  4. .Net Class Library
  5. Classes and Objects
  6. PowerShell Class
  7. C# Class
  8. Object Introspection
  9. Inspecting PowerShell objects for properties and methods
  10. Inspecting C# objects for properties and methods
  11. Inspecting Constructors in C# objects
  12. typeof() vs GetType() vs ‘is’
  13. Class Members
  14. Fields and Properties
  15. PowerShell Class Properties
  16. Default values to PowerShell class properties
  17. PowerShell Cast initialization
  18. Static Properties in PowerShell
  19. C# Class Fields, Properties, and Accessors
  20. Fields
  21. Properties and Accessors
  22. Initial values to C# class properties
  23. Static Properties in C#
  24. C# Object Initializer
  25. Methods
  26. PowerShell Class Methods
  27. Static methods in PowerShell Class
  28. Instance methods in PowerShell Classes
  29. C# Class Methods
  30. Static methods in C# Class
  31. Instance methods in C# Class
  32. Constructors
  33. Constructors in PowerShell Classes
  34. Constructors in C# Classes
  35. Summary
  36. Key Pointers
  37. Exercises and Assignments
  38. Reading Recommendations

Chapter 3: Variables

  1. Purpose of the Chapter
  2. Introduction
  3. Value Types
  4. Reference Types
  5. Naming conventions
  6. Naming PowerShell variables
  7. Naming C# variables
  8. Declaring variables
  9. Constant variables
  10. Clearing and un-setting values of variables
  11. Variable scopes
  12. Variable scopes in PowerShell scripts
  13. Variable scopes with C# Classes
  14. Class level scope
  15. Method level scope
  16. Block level Scope
  17. Summary
  18. Key Pointers
  19. Exercises and Assignments
  20. Reading Recommendations

Chapter 4: Console Input and Output

  1. Purpose of the Chapter
  2. Introduction
  3. What is a Console?
  4. Standard Input and Output
  5. Writing to Console
  6. Writing without a New-Line
  7. Reading from Console
  8. Reading numeric values
  9. Reading keys from Console
  10. Reading from Console Securely
  11. Clearing the Console
  12. Summary
  13. Key Pointers
  14. Exercises and Assignments
  15. Reading Recommendations

Chapter 5: Passing Command-line Arguments

  1. Purpose of the Chapter
  2. Introduction
  3. Parameters and arguments
  4. $args Automatic Variable in PowerShell
  5. Main() and args in C# command-line applications
  6. Params() in PowerShell
  7. Environment.GetCommandLineArgs() method in .Net
  8. Summary
  9. Key Pointers
  10. Exercises and Assignments
  11. Reading Recommendations

Chapter 6 - Collections

  1. Introduction
  2. Generic collections
  3. Non-Generic collections
  4. Array
  5. ArrayList
  6. List
  7. HashTable
  8. Dictionary
  9. Stack
  10. Queue
  11. HashSet
  12. Exercises and Assignments
  13. Reading Recommendations

Solutions to Exercises

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub