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
Activity: Scripting Administrative Tasks
PowerShell.
#Task:Get a list of last logon times for all users in a specific organizational unit.
#Output the list to a text file named userlastlogontxt
#Import the ActiveDirectory Module
ImportModule ActiveDirectory
# Define the Organizational Unit OU Path for HR
$OU OUHRDCPRACTICELABS,DCcom"
# Get all user objects in the OU and their lastLogonTimestamp
$users GetADUser Filter SearchBase $OU Property lastLogonTimestamp
# Convert the lastLogonTimestamp to a readable date and select the necessary properties
$userLogons $users SelectObject Name,@Name'LastLogonDate';ExpressionDateTime::FromFileTime$lastLogonTimestamp
# Export the list to a text file
$userLogons OutFile "userlastlogontxt
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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
