删除用户配置文件 (正则表达式)

$parttern = "\b\d{6}\b"

$today = Get-Date

$hostname = "cnhzpd-47d173x"

$profiles = Get-WmiObject -Class win32_userprofile -ComputerName $hostname | Select-Object -Property LocalPath, @{N='time'; E={$_.ConverttoDateTime($_.lastusetime)}}, @{N='Delta';E={$today - $_.ConverttoDateTime($_.lastusetime)}} | where {$_.localpath.substring(9,6) -match $parttern -and $_.delta -gt '6.0:0:0'}

foreach($profile in $profiles) { (Get-WmiObject -class Win32_UserProfile -ComputerName $hostname | where {$_.localpath -eq $profile.localpath}).delete()

}

 

你可能感兴趣的:(正则表达式)