LONG ROUTES PathTooLongException POWERSHELL

0

I have a small problem with a script, I want to send an HTML report to the support group of my company through powershell ...

The truth about the case well the script is simple. Until I've touched on this.

I really do not know what to do ... there is an option to enable access to routes with long names but on my 2012 server there is no such option.

I have managed to send space alerts .. But this has left me touched since I am starting with PS and I do not know where to throw ..............

I attach the code you are my last hope.

    <#
    Server Disk Space monitoring Report HTML
#>

#Mail param
$mailTo   = "mail"
$mailFrom = "mail"
$mailSubject = "ALERTA ESPACIO "

$computer = "localhost"

#Space alert disk 10%
$alertSpace = 10

$tableReporting= Get-CimInstance -ComputerName $computer cim_LogicalDisk -erroraction 'SilentlyContinue' '
| Select SystemName, DriveType, Name, @{n='Size (GB)' ;e={"{0:n2}" -f($_.size/1gb)}}, @{n='FreeSpace (GB)' ;e={"{0:n2}" -f ($_.freespace/1gb)}}, @{n='PercentFree';e={"{0:n2}" -f ($_.freespace/$_.size*100)}} '
| Where-Object {$_.DriveType -eq 3 -and $_.PercentFree -lt $alertSpace} '
| ConvertTo-HTML -Fragment

$largeFiles = gci -r  | sort -descending -property length | Where-Object {$_.Length -gt 15GB};{$_.FullName.Length -gt 260} |Select-Object Name,Directory,@{n='GB';e={"{0:N2}" -F ($_.length/ 1GB)}} |select Name, Directory, GB

#---- Begin HTML email report ----

$HTMLmessage = @"

<font color=""Red"" face=""Segoe UI Light, Segoe UI Light"" size=""8"">

<u>
    <b>Disk Space Storage Report</b>
</u>

<br>
<br>

    This report was generated because the drive X:\ listed below have less than $alertSpace% free space.

<br>
<br>

<style type=""text/css"">

body{
    font: .8em ""Segoe UI Light"", Segoe UI Light, Segoe UI Light, Segoe UI Light, Segoe UI Light;
    }

ol{
   margin:2;
   padding: 0 1.5em;
   }

table{
      color: #000000;background:#e60000;
      border-collapse:collapse;
      width:647px;
      border:2px solid #808080;
      }

thead{}

thead th{
        padding:1em 1em .5em;
        border-bottom:1px dotted #FFF;
        font-size:120%;
        text-align:left;
        }

thead tr{}

td{
   padding:.5em 1em;
   }

tfoot{}

tfoot td{padding-bottom:1.5em;}

tfoot tr{}

#middle{background-color:#900;}

</style>

<body>

    $tableReporting

    <br>
    <br>


</body>
    <u>
        <b>Large files in X file server</b>
    </u>
    <br>
    <br>

    $largeFiles

    <br>
    <br>

    <img src="C:\logo.png"> 

"@


#---- End HTML email report ----

$regexsubject = $HTMLmessage
$regex = [regex] '(?im)<td>''

if($regex.IsMatch($regexsubject)){
    Send-MailMessage -To $mailTo -From $mailFrom  -Subject $mailSubject -BodyAsHtml -Body $HTMLmessage -Priority High -SmtpServer "server.mail"
}

Thank you ...

    
asked by Andres Cabrera 04.01.2019 в 14:56
source

0 answers