-
-
Save kvprasoon/e8146706a2873f815779 to your computer and use it in GitHub Desktop.
Scripting Games March 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Helped MSDN reference https://msdn.microsoft.com/en-us/library/20bw873z.aspx | |
#region Beginner | |
Invoke-Command -ComputerName Fileserver -ScriptBlock { Get-ChildItem -Path 'C:\powershell.org\Scripting Games\FileShare' -Recurse -File | | |
Where-Object -FilterScript { @('©','¼','½','÷') -notcontains $_.Name -and [regex]::IsMatch($_.Name,"\p{IsLatin-1Supplement}") } | | |
Format-Table @{ L='Name';E='Name' },@{ L='Directory';E='directoryname' },@{ L='Creation Date';E='CreationTime' },@{ L='Last Modification Date';E='LastWriteTime' },@{ L='File Size';E='Length' } } | |
#endregion Beginner | |
#region Advanced | |
#Job Script | |
Invoke-Command -ComputerName fileserver -ScriptBlock { Register-ScheduledJob -Name 'Find files with diacritical marks' -FilePath "\\server\c$\Scripts\GeTDiacritics.ps1" -Trigger (New-JobTrigger -DaysOfWeek Saturday -WeeksInterval 2 -At '11:00 PM' -Weekly) } | |
#region GetDiacritics.ps1 | |
Function Get-Diacritic | |
{ | |
process | |
{ | |
[string]$path='\\server\C$\FileShare' | |
$Date=Get-Date | |
$OutFile="$env:TEMP\{0}{1:D2}{2}_FileNamesWithDiacritics.csv " -f $Date.Year,$Date.Month,$Date.Day | |
$DFiles=Get-ChildItem -Path $path -Recurse -File -ErrorAction Stop | | |
Where-Object -FilterScript { $_.Name -notmatch '[©¼½÷]' -and ([regex]::IsMatch($_.Name,"\p{IsLatin-1Supplement}")) } | | |
Select-Object -Property @{ L='Name';E='Name' },@{ L='Directory';E='directoryname' },@{ L='Creation Date';E='CreationTime' },@{ L='Last Modification Date';E='LastWriteTime' },@{ L='File Size';E={"{0:0.00}KB" -f ($_.length/1KB)} } | |
$Content = "Scan of $($Date.ToShortDateString()). $($DFiles.Count) filenames with diacritics marks found under $path" | |
if($DFiles.Count -ne 0) | |
{ | |
$DFiles | Export-Csv -Path $OutFile -NoTypeInformation | |
$ContentHTML = $DFiles | ConvertTo-Html -Head "<h4 style='color:blue;'> Scan of $($Date.ToShortDateString()). $($DFiles.Count) filenames with dicritics marks found under $path </h4>" -PostContent "<p style='color:orange;'>Generated by PowerShell </p>" -as Table | |
$Content = $Content.ToString() | |
} | |
Send-MailMessage -Body $Content -BodyAsHtml -To 'Toaddress@mail.com' -From 'fromaddresss@mail.com' -SmtpServer 'smtpserver.mail.com' -Subject 'Files with Diacritical Marks' | |
} | |
} | |
Get-Diacritic | |
#endregion GetDiacritics.ps1 | |
#endregion Advanced |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment