1. Home
  2. /
  3. Powershell
  4. /
  5. Factorial

Factorial - Powershell Typing CST Test

Loading…

Factorial — Powershell Code

Recursive factorial function.

function Factorial($n) {
	if ($n -le 1) { return 1 }
	else { return $n * (Factorial ($n - 1)) }
}

Write-Host "Factorial of 5: $(Factorial 5)"

Powershell Language Guide

PowerShell is a cross-platform task automation and configuration management framework, combining a command-line shell, scripting language, and object-based pipeline built on .NET. It is widely used for DevOps, system administration, cloud automation, and enterprise workflows.

Primary Use Cases

  • ▸System administration & configuration
  • ▸Cloud automation (Azure & Microsoft 365)
  • ▸DevOps & CI/CD pipelines
  • ▸Remote management & orchestration
  • ▸File management & process automation
  • ▸Infrastructure as Code (IaC) scripting

Notable Features

  • ▸Object-based pipeline
  • ▸Rich cmdlets and modules
  • ▸Native .NET integration
  • ▸Cross-platform support
  • ▸Powerful remoting capabilities

Origin & Creator

Created by Microsoft, originally released in 2006 as 'Monad' before becoming Windows PowerShell, then PowerShell Core (open-source).

Industrial Note

PowerShell dominates enterprise automation across Windows Server, Azure, Active Directory, Intune, Office 365, and hybrid-cloud DevOps environments.

Quick Explain

  • ▸PowerShell is both a shell and a powerful scripting language.
  • ▸It automates system tasks, cloud operations, server management, and DevOps pipelines.
  • ▸It uses an object-based pipeline, passing .NET objects instead of plain text.

Core Features

  • ▸Cmdlets (Get-*, Set-*, New-*, Remove-*)
  • ▸Advanced functions
  • ▸Modules & packages (PSGallery)
  • ▸PowerShell Remoting
  • ▸Error handling via try/catch/finally
  • ▸Object filtering & formatting

Learning Path

  • ▸Learn cmdlets & pipeline
  • ▸Understand objects & formatting
  • ▸Write functions & scripts
  • ▸Explore modules & remoting
  • ▸Build automation systems

Practical Examples

  • ▸Active Directory automation
  • ▸Azure resource provisioning
  • ▸Scheduled maintenance scripts
  • ▸System inventory tools
  • ▸CI/CD deployment automation

Comparisons

  • ▸More powerful than Bash for Windows automation
  • ▸More enterprise-oriented than Python for system tasks
  • ▸More structured than CMD
  • ▸More cross-platform than legacy Windows PowerShell
  • ▸Less lightweight than POSIX shells

Strengths

  • ▸Object pipeline avoids string parsing
  • ▸Deep integration with Windows & Azure
  • ▸Enterprise-grade automation
  • ▸Extensible with .NET
  • ▸Powerful remoting & orchestration

Limitations

  • ▸Slower startup vs shells like Bash
  • ▸Learning curve due to object model
  • ▸Platform differences between Windows & Linux
  • ▸Heavy for simple one-liners
  • ▸Verbose syntax compared to POSIX shells

When NOT to Use

  • ▸High-performance computing
  • ▸Large-scale GUI applications
  • ▸Tiny scripts better suited to Bash
  • ▸Cross-shell POSIX scripting
  • ▸Math-heavy workloads

Cheat Sheet

  • ▸Get-Help <cmdlet>
  • ▸Get-Command
  • ▸Get-Member
  • ▸Import-Module
  • ▸$PSVersionTable

FAQ

  • ▸Is PowerShell cross-platform?
  • ▸Yes - runs on Windows, Linux, and macOS.
  • ▸Is PowerShell only for Windows?
  • ▸No - PowerShell Core is fully cross-platform.
  • ▸Is PowerShell better than Bash?
  • ▸For Windows environments-absolutely.
  • ▸Is it good for DevOps?
  • ▸Yes, especially for Azure, CI/CD, and automation.

30-Day Skill Plan

  • ▸Week 1: Cmdlets, pipeline, objects
  • ▸Week 2: Functions, modules, remoting
  • ▸Week 3: Error handling, workflows
  • ▸Week 4: Azure/AD automation projects

Final Summary

  • ▸PowerShell is a premier automation language for enterprise IT.
  • ▸Its object pipeline enables robust and reliable automation.
  • ▸Perfect for Windows, Azure, and cloud-integrated workflows.
  • ▸Extensible, scalable, and built for professional DevOps.

Project Structure

  • ▸scripts/ automation scripts
  • ▸modules/ reusable components
  • ▸profile.ps1
  • ▸config.json
  • ▸logs/ execution logs

Monetization

  • ▸DevOps automation roles
  • ▸Cloud engineering
  • ▸Systems administration
  • ▸Infrastructure consulting
  • ▸Azure automation freelancing

Productivity Tips

  • ▸Use aliases for speed
  • ▸Learn common cmdlets deeply
  • ▸Leverage -WhatIf and -Confirm
  • ▸Use profiles for shortcuts
  • ▸Reuse modules instead of rewriting

Basic Concepts

  • ▸Cmdlets
  • ▸Pipelines
  • ▸Variables & objects
  • ▸Functions & modules
  • ▸Remoting & sessions

Official Docs

  • ▸Microsoft Learn PowerShell
  • ▸PowerShell GitHub Documentation
  • ▸Get-Help

More Powershell Typing Exercises

PowerShell Counter and Theme TogglePowerShell Simple CalculatorPowerShell Fibonacci SequencePowerShell Array ComprehensionPowerShell Hashtable FilteringPowerShell Anonymous FunctionsPowerShell Sum of ArrayPowerShell Zip ArraysPowerShell String Manipulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher