Reputation: 13
I'm hoping that someone will be able to offer some guidance. I'm trying to build a Powershell Script that enables me to get the LastPasswordChangeStamp for members of specific security group. The group I'm testing with has 10 members but when I run the script, it behaves as follows:
Code below:
#Define the Security Group
$securityGroup = Get-MsolGroup -GroupType “Security” | Where-Object {$_.DisplayName -eq “GroupName”}
# Get Members
$securityGroupMembers = Get-MsolGroupMember -GroupObjectId $securityGroup.ObjectId
# Iterate each user
ForEach($Member in $securityGroupMembers){
#Get underlying msol user
#$user = Get-MsolUser -ObjectId -$mUser.ObjectId
#Determine password age
Get-MsolUser | select DisplayName, LastPasswordChangeTimeStamp
}
I cant see why its looping multiple times and was hoping someone could offer some guidance on where I'm going wrong.
Thanks for your help
Upvotes: 1
Views: 301
Reputation: 2766
The issue here is in your foreach Loop. you're saying For each member in the group, Get all users in your entire tenant, and display their displayname and lastpasswordchangetimestamp.
you can replace that entire foreach loop with
$securityGroupMembers | get-msoluser | select DisplayName, LastPasswordChangeTimeStamp
just delete the entire foreach loop.
Upvotes: 1