zhaoke0727 发表于 2018-6-25 07:09:37

Powershell Scripting Game - March 2016

function Get-Diacritic  
{
  
   
  

  
    Param
  
    (
  
      # Param1 help description
  
      [Parameter(
  
                   ValueFromPipelineByPropertyName=$true,
  
                   Position=0)]
  
      $Path=".\"
  
    )
  
    Begin
  
    {
  
    }
  
    Process
  
    {
  

  
      Get-ChildItem -Recurse -Path $path|
  
      Where-Object {$_.name -match "[\u00C0-\u00FF]"} |
  
      select Name, directory, creationtime, lastwritetime,
  
      @{
  
      n="Size";
  
      e={
  
      if($_.length -lt 1000){"{0:n1}" -f $_.length.tostring()+" Byte"}
  
      elseif($_.length -lt 1000000){("{0:n1}" -f ($_.length/1kb)).ToString()+" KB" }
  
      else{("{0:n1}" -f ($_.length/1mb)).ToString() + " MB"}
  
      }
  
      } | tee -Variable file
  
      if($file -eq $null){Write-Warning "No file name dectected with Latin Character"}
  
      else{
  
      $name=(get-date -Format yyyy.M.d)+"FileNamesWithDiacritics.csv"
  

  
      $file | export-csv c:\temp\$name -Encoding Unicode}
  
      $from = "abc@test.com"
  
      $to = "def@test.com"
  
      $smtp = "smtp.office365.com"
  
      $sub = "file list"
  

  
      $Body = $file | ConvertTo-Html -Head "Scanning Result" -As Table | Out-String
  
      $attach="c:\temp\"+$name
  
      $secpasswd = ConvertTo-SecureString "Password" -AsPlainText -Force
  
      $mycreds = New-Object System.Management.Automation.PSCredential ($from, $secpasswd)
  
      Send-MailMessage -To $to -From $from -Subject $sub -Body $body -Credential $mycreds -SmtpServer $smtp -DeliveryNotificationOption Never -BodyAsHtml -UseSsl -port 587 -Attachments $attach
  
    }
  
    End
  
    {
  
    }
  
}
  

  
Get-Diacritic c:\users\yli\Downloads
页: [1]
查看完整版本: Powershell Scripting Game - March 2016