Welcome to the world of PowerShell! This page offers examples of how to use various PowerShell modules to create powerful automation scripts.
Let's explore how to import data from a CSV file using the 'Import-Csv' module.
1. Save your CSV file (e.g., 'data.csv').
2. Open PowerShell and run: Import-Csv data.csv
This will load the data into a PowerShell object.
We'll get all users from Active Directory using 'Get-ADUser'.
1. Open PowerShell and run: Get-ADUser -Filter 'Name -like "*Azure PowerShell*" -Properties DisplayName, SamAccountName, GivenName, Surname, EmailAddress, Title'
This retrieves all users with 'Azure PowerShell' in their name.
We'll demonstrate looping through a list of objects using a for loop.
1. Define a list of objects: $objects = @(1, 2, 3)
2. Run: foreach ($object in $objects) { ... }
This will execute the code for each object in the list.
Here's an example demonstrating the 'Get-Member' cmdlet and retrieving object properties.
1. Run: Get-Member -Method GetMember -MemberType Property -MemberType String -InputObject $objects
This will display properties of each object in the array.