added domain name variable
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
# Delete old profiles based off of the last login in AD
|
# Delete old profiles based off of the last login in AD
|
||||||
|
|
||||||
$daysInactive = 14 # Specify the number of days of inactivity
|
$daysInactive = 14 # Specify the number of days of inactivity
|
||||||
$inactiveDate = (Get-Date).AddDays(-$daysInactive)
|
|
||||||
$homeDirectoryPath = "C:\Users" # Path to user home directories
|
$homeDirectoryPath = "C:\Users" # Path to user home directories
|
||||||
|
$domainName = "local" # Domain name that the pc is on
|
||||||
|
|
||||||
|
|
||||||
|
$inactiveDate = (Get-Date).AddDays(-$daysInactive)
|
||||||
|
|
||||||
# Get all user profiles
|
# Get all user profiles
|
||||||
Get-WmiObject Win32_UserProfile | ForEach-Object {
|
Get-WmiObject Win32_UserProfile | ForEach-Object {
|
||||||
@@ -11,7 +14,7 @@ Get-WmiObject Win32_UserProfile | ForEach-Object {
|
|||||||
$userName = $profile.LocalPath.Split('\')[-1] # Get the username from the folder path
|
$userName = $profile.LocalPath.Split('\')[-1] # Get the username from the folder path
|
||||||
|
|
||||||
# Get the last logon time for the local user
|
# Get the last logon time for the local user
|
||||||
$userLogon = Get-WmiObject -Class Win32_NetworkLoginProfile -Filter "Name='RPBLUEJAYS\\$userName'" | Select-Object -Property LastLogon
|
$userLogon = Get-WmiObject -Class Win32_NetworkLoginProfile -Filter "Name='$domainName\\$userName'" | Select-Object -Property LastLogon
|
||||||
|
|
||||||
if ($userLogon) {
|
if ($userLogon) {
|
||||||
$lastLogonDate = [Management.ManagementDateTimeConverter]::ToDateTime($userLogon.LastLogon)
|
$lastLogonDate = [Management.ManagementDateTimeConverter]::ToDateTime($userLogon.LastLogon)
|
||||||
|
|||||||
Reference in New Issue
Block a user