Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thegooddoctorgonzo/8bb2364dfd1942e1183e467c4cfe5c37 to your computer and use it in GitHub Desktop.

Select an option

Save thegooddoctorgonzo/8bb2364dfd1942e1183e467c4cfe5c37 to your computer and use it in GitHub Desktop.
:
$folders = Get-ChildItem -Path \\SHAREPATH\ProfileUnity\ -Depth 0 -Directory | Where-Object {$_.name -ne "_ToBeDeleted"}
$files = New-Object System.Collections.ArrayList
$objTemplateObject = New-Object -TypeName psobject
$objTemplateObject | Add-Member -MemberType NoteProperty -Name Name -Value $null
$objTemplateObject | Add-Member -MemberType NoteProperty -Name Profile -Value $null
$objTemplateObject | Add-Member -MemberType NoteProperty -Name LastLogindDate -Value $null
$objTemplateObject | Add-Member -MemberType NoteProperty -Name ProfileGroup -Value $null
$objList = New-Object System.Collections.ArrayList
$oldLogons = 0
$cutOffDate = Get-Date -Date 08/20/2021
foreach($folder in $folders)
{
if($file = Get-ChildItem -Path "$($folder.FullName)\Logs" -Name "client_Logon_PEOAVN_*" | Select-Object -Last 1)
{
$objTemp = $objTemplateObject | select *
$objTemp.Name = (Get-Item -Path $file.PSPath).Directory.Parent.Name
$objTemp.Profile = ((Get-Content -Path $file.PSPath)[16].Split("\") | select -Last 1).split(".")[0]
$objTemp.LastLogindDate = get-date -date ((Get-Item -Path $file.PSPath).LastWriteTime) -Format yyyyMMdd
if((get-date -date ((Get-Item -Path $file.PSPath).LastWriteTime)) -lt $cutOffDate)
{
$oldLogons++
}
$groups = Get-ADUser -Identity $objTemp.name -Properties memberof | Select-Object -ExpandProperty memberof
$objTemp.ProfileGroup = (($groups | Where-Object {$_ -like "*ProfileUnity*"}).split(",")[0]).trim("CN=")
$objList.Add($objTemp) | Out-Null
}
}
$dailyCsvFile = "C:\Temp\PUupdate.csv"
$objList | Export-Csv -Path $dailyCsvFile -Force
$counts = $objList | Group-Object -Property Profile | Select-Object Count,Name
$counts | Out-File c:\temp\bodytext.txt
$totalCsvFile = "C:\Scripts\ReportGetUsersCurrentProUConfig\ProfileUnityConfigsDailyCount.csv"
[string]$date = Get-date -Format yyyyMMdd
[string]$migProd = $counts | where {$_.name.trimEnd() -like "Win10v3 - Migrated - Production*"} | Select-Object -ExpandProperty Count
[string]$step1 = $counts | where {$_.name.trimEnd() -like "Win10v3 - Step1*"} | Select-Object -ExpandProperty Count
[string]$reprofiler = $counts | where {$_.name.trimEnd() -like "Win10v3 - MigProdReprofiler*"} | Select-Object -ExpandProperty Count
[string]$def = $counts | where {$_.name.trimEnd() -like "PEO_Default"} | Select-Object -ExpandProperty Count
if($null -in $migProd,$step1,$reprofiler,$def)
{
if($migProd -eq $null)
{
$migProd = 0
}
if($step1 -eq $null)
{
$step1 = 0
}
if($reprofiler -eq $null)
{
$reprofiler = 0
}
if($def -eq $null)
{
$def = 0
}
}
$outRow = '"' + "$date" + '"' + "," + '"' + "$migProd" + '"' + "," + '"' + "$step1" + '"' + "," + '"' + "$reprofiler" + '"' + "," + '"' + "$def" + '"'
$outrow | Out-File -FilePath $totalCsvFile -Append
$body = Get-Content -Path C:\temp\bodytext.txt -Raw
$body = $body + "`n`nUsers not logged in since Aug 20, 2021 `n-----------`n$oldLogons"
$subject = "Profile Unity User Config AND PROFILE GROUPS!"
#$to = "[email protected]","[email protected]"
$to = "[email protected]" ,"[email protected]"
Send-MailMessage -Body $body -Subject $subject -From "[email protected]" -To $to -SmtpServer "smtpgw.DOMAIN" -Port 25 -Attachments $dailyCsvFile,$totalCsvFile
#let's cleanup the temp file
Remove-Item -Path $csvfile -Force -ErrorAction SilentlyContinue
Remove-Item -Path "C:\temp\bodytext.txt" -Force -ErrorAction SilentlyContinue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment