Hi Friends,
I am just beginner for power shell. In My project required list of users lastlogon from AD forest. I am searched multiple forum and i make it my own script.
#Get Domain List from Forest
$csv = “D:\scripts\LastLogon-users.csv”
$users = Get-Content “D:\users.txt”
$array = @()
Import-Module activedirectory
$Domains = (Get-ADForest ‘testlab.com’).Domains
#Search on each domain
foreach($Domain in $Domains)
{
foreach($user in $users)
{
$svc = Get-ADUser -Filter 'Name -like "$user"' -server '$domain' | Get-ADObject -Properties lastLogontimeStamp
$obj = New-Object psobject -Property @{
ADUser = $user
UserName = $svc.SamAccountName
LastLogonTimeStamp = $svc.LastLogonTimeStamp
}
$array += $obj
}
}
$array | export-csv $CSV -NoTypeInformation
I am getting below error . can you someone please help on this.
[b]
[blockquote]{Get-ADUser : Invalid URI: The server name ‘$domain’ could not be parsed. You might need to enable internationalized dom
ain name support for class System.Uri. See help of class System.Uri for more details.
At D:\Scripts\Get-Users-LastLogon.ps1:16 char:21
-
$svc = Get-ADUser <<<< -Filter "Name -like "$user"" -server "$domain" | Get-ADObject -Properties lastLogont
imeStamp
+ CategoryInfo : InvalidType: [:] [Get-ADUser], UriFormatException
+ FullyQualifiedErrorId : Invalid URI: The server name "$domain" could not be parsed. You might need to enable int
ernationalized domain name support for class System.Uri. See help of class System.Uri for more details.,Microsoft.
ActiveDirectory.Management.Commands.GetADUser}[/blockquote][/b]
Edit : Issue has been fixed by change this line "Get-ADUser -Filter 'Name -like $user' -server $domain | Get-ADObject -Properties lastLogontimeStamp"