Question: CYB 3 0 0 6 - 3 Activity: Scripting Administrative Tasks PowerShell. #Task 2 :Get a list of last logon times for all users in

CYB 300
6-3 Activity: Scripting Administrative Tasks
PowerShell.
#Task2:Get a list of last logon times for all users in a specific organizational unit.
#Output the list to a text file named user_last_logon.txt
#Import the ActiveDirectory Module
Import-Module ActiveDirectory
# Define the Organizational Unit (OU) Path for HR
$OU ="OU=HR,DC=PRACTICELABS,DC=com"
# Get all user objects in the OU and their lastLogonTimestamp
$users = Get-ADUser -Filter *-SearchBase $OU -Property lastLogonTimestamp
# Convert the lastLogonTimestamp to a readable date and select the necessary properties
$userLogons = $users | Select-Object Name,@{Name='LastLogonDate';Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}}
# Export the list to a text file
$userLogons | Out-File "user_last_logon.txt"
I would appreciate your help to analyze the script that I created and works fine on powerShell.
a. Script contains a repetition structure
b. Script contains a compound conditional statement
c. Script contains variable declaration and usage
CYB 3 0 0 6 - 3 Activity: Scripting

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!