Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $FILESERVER = "File server name"
- $group = Get-ADGroupMember -Identity "AD Group Name"
- $groupname = $group.name
- $findusercomputer = $null
- # Connect Remotely to Server, Run Session, get a list of everybody logged in there
- $S=NEW-PSSESSION –computername $FILESERVER
- $Results=(INVOKE-COMMAND –Session $s –scriptblock { (NET SESSION) })
- REMOVE-PSSESSION $S
- foreach($name in $groupname){
- $Username = Get-ADUser -filter * -Properties samaccountname, cn | Where-Object cn -like "$name" | select samaccountname
- $username = $username.samaccountname
- $R = $results | Select-String $Username
- Foreach ( $Part in $R ) {
- $ComputerIP=$Part.Line.substring(2,21).trim()
- $User = $Part.Line.substring(21,44).trim()
- # Use nslookup to identify the computer, grab the line with the “Name:” field in it
- $Computername=([System.Net.dns]::GetHostbyAddress("$ComputerIP"))
- $computername = $ComputerName.HostName
- If ($Computername -ne $NULL) {
- #Else { $Computername=$Computername.substring(9).trim()}
- # “$User is on $Computername with IP $ComputerIP”
- [array]$findusercomputer += $computername
- }
- }
- }
- $findusercomputer
Advertisement
Add Comment
Please, Sign In to add comment