Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

find computers account with powershell v2 cause xp

$
0
0

hello guys ,

i want to find all inactives computers  for 3 months, i started my script with my powershell book :)

But i have message between $(Get-Date)).days ........

Missing closing ')' in expression in Powergui

I dont know why , and i test the script whithout where cmdlet , i got the last connexion date but at 01/01/1601

i want to resolve the two problems and get the solution.

and i try to use dsquery computer -inactive 12 and i get the result but i want the lastlogon date without an error.

# Comptes d'ordinateurs inactivés
param ($NonConnecteDepuisNbJours=30)
[datetime]$date = '01/01/1601'

$objdomain = [ADSI]''
$objRecherche = New-Object System.DirectoryServices.DirectorySearcher($objdomain)
$requete = '(&(objectCategory=Computer)(name=*))'
$objRecherche.Filter=$requete
$comptes = $objRecherche.findall()

$comptes | Select-Object @{e={$_.properties.cn};n='Nom Commun'},
@{e={$date.AddTicks($($_.properties.lastlogontimestamp))};n='Dernière Connexion'}|
Where-Object {(New-TimeSpan $_."Dernière Connexion"
$(Get-Date)).days -ge $NonConnecteDepuisNbJours
}

But

datetime]$date='01/01/1601'

$objdomain

= [ADSI]''

$objRecherche

=New-ObjectSystem.DirectoryServices.DirectorySearcher($objdomain)

$requete

='(&(objectCategory=Computer)(name=*))'

$objRecherche

.Filter=$requete

$comptes

=$objRecherche.findall()

$comptes

| Select-Object @{e={$_.properties.cn};n='Nom Commun'},

@{e

={$date.AddTicks($($_.properties.lastlogontimestamp))};n='Dernière Connexion'}|

Where-Object

{(New-TimeSpan$_."Dernière Connexion"

$(

Get-Date)).days-ge$NonConnecteDepuisNbJours

}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>