Variables and Data Types
The Script That Finally Made Sense
Get-Service -Name "wuauserv" | Stop-Service
Get-Service -Name "wuauserv" | Start-Service
Get-Service -Name "wuauserv" | Select-Object Status$service = Get-Service -Name "wuauserv"
$service | Stop-Service
$service | Start-Service
$service.StatusUnderstanding Variables
Creating Variables
# Simple assignment
$name = "PowerShell"
$number = 42
$date = Get-Date
$processes = Get-Process
# Variables can be reassigned
$count = 1
$count = 100
$count = "Now I'm a string" # PowerShell is dynamically typedVariable Names
Naming Best Practices
PowerShell Data Types
Common Data Types
Type Checking
Explicit Type Declaration
Type Conversion
Working with Strings
String Creation
String Operations
String Comparison
Arrays
Creating Arrays
Accessing Array Elements
Array Operations
Iterating Arrays
Array Type
Hashtables
Creating Hashtables
Accessing Hashtable Values
Modifying Hashtables
Iterating Hashtables
Real-World Hashtable Use
Automatic Variables
Variable Scope
Scope Levels
Scope Inheritance
Real-World Examples
Configuration Management
Data Collection and Reporting
Common Pitfalls
1. Uninitialized Variables
2. Variable Scope Confusion
3. Array Mutation Confusion
4. Hashtable Key Case Sensitivity
Key Takeaways
What You've Learned
Next Steps
Last updated