PowerShell - Basics and EnvironmentYou want to write a script that works on Windows and Linux to list files. Which approach is best?AWrite a PowerShell script using Get-ChildItem and run PowerShell Core on both OSBWrite a Bash script using ls and run it only on LinuxCWrite a CMD batch file using dir and run it on Windows onlyDWrite separate scripts for each OS and manually switchCheck Answer
Step-by-Step SolutionSolution:Step 1: Consider cross-platform supportPowerShell Core (PowerShell 7+) runs on Windows and Linux, supporting Get-ChildItem on both.Step 2: Evaluate other optionsBash scripts work only on Linux/macOS; CMD batch files only on Windows; separate scripts add complexity.Final Answer:Write a PowerShell script using Get-ChildItem and run PowerShell Core on both OS -> Option AQuick Check:Cross-platform scripting = PowerShell Core + Get-ChildItem [OK]Quick Trick: PowerShell Core runs cross-platform, unlike CMD or Bash alone [OK]Common Mistakes:Assuming Bash works on Windows by defaultThinking CMD scripts run on LinuxIgnoring cross-platform PowerShell Core availability
Master "Basics and Environment" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Cmdlets and Pipeline - Where-Object for filtering - Quiz 11easy Cmdlets and Pipeline - Get-Member for object inspection - Quiz 4medium Cmdlets and Pipeline - Where-Object for filtering - Quiz 12easy Control Flow - For loop - Quiz 4medium Operators - String comparison (-like, -match) - Quiz 11easy Operators - Why operators perform comparisons and logic - Quiz 5medium Operators - Range operator (..) - Quiz 6medium Variables and Data Types - Integer and floating-point types - Quiz 7medium Variables and Data Types - Boolean values - Quiz 4medium Variables and Data Types - Automatic variables ($_, $PSVersionTable) - Quiz 9hard