{ Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 }
$whitespace = ".capacity.htm"
$checkrep = Test-Path ".capacity.htm"
If ($checkrep -like "True")
{ Remove-Item ".capacity.htm"
}
New-Item ".capacity.htm" -type file
$MessageParams = @{
From = 'abc@test.com'
To = "admin@test.com"
subject = "CAPACITY $((get-date).ToShortDateString())"
SMTPServer = 'smtpserver'
}
Add-Content $whitespace "<html>"
Add-Content $whitespace "<head>"
Add-Content $whitespace "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859 1'>"
Add-Content $whitespace '<title>Mailbox DB Capacity Management Report</title>'
add-content $whitespace '<STYLE TYPE="text/css">'
add-content $whitespace "<!–"
add-content $whitespace "td {"
add-content $whitespace "font-family: Consolas;"
add-content $whitespace "font-size: 12px;"
add-content $whitespace "border: 1px solid #999999;"
add-content $whitespace "padding: 0px;border-collapse:collapse;"
add-content $whitespace "margin: 3px;"
add-content $whitespace "}"
add-content $whitespace "building {"
add-content $whitespace "margin: 5px;"
add-content $whitespace "}"
add-content $whitespace "table {"
add-content $whitespace "border: thin solid #000000; padding:0px;"
add-content $whitespace "}"
add-content $whitespace "–>"
add-content $whitespace "</style>"
Add-Content $whitespace "</head>"
Add-Content $whitespace "<building><p>Your info text</p>"
add-content $whitespace "<table>"
Add-Content $whitespace "<tr bgcolor='BlanchedAlmond'>"
Add-Content $whitespace "<td align='center'><B>DB Name</B></td>"
Add-Content $whitespace "<td align='center'><B>Server</B></td>"
Add-Content $whitespace "<td align='center'><B>DB Size(GB)</B></td>"
Add-Content $whitespace "<td align='center'><B>WhiteSpace(GB)</B></td>"
Add-Content $whitespace "<td align='center'><B>LastFullBackup</B></td>"
Add-Content $whitespace "<td align='center'><B>LastIncrementalBackup</B></td>"
Add-Content $whitespace "</tr>"
$databases = Get-MailboxDatabase -Status | ?{$_.Recovery -ne "$True"} | sort -Descending DatabaseSize,
AvailableNewMailboxSpace
foreach($Database in $databases)
{
Write-Host $Database.Name `t $Database.Server `t $Database.DatabaseSize `t $Database.AvailableNewMailboxSpace -ForegroundColor Green
$currdate = ( Get-Date ).ToString('dd/MM/yyyy')
$ServerName = $Database.Server
$machineName = $Database.Name
$dbsize = $Database.DatabaseSize.ToGB()
$svcState = $Database.AvailableNewMailboxSpace.ToGB()
$lstfull = $Database.LastFullBackup
if ( $lstfull -eq $null){ $lstfull = "Alert!"}else{
$lstfull = $lstfull.ToString('dd/MM/yyyy')
$lastFullBackup = $Database.LastFullBackup; $currentDate = Get-Date
$howOldBkpFull = $currentDate – $lastFullBackup
$howOldBkpFull = $howOldBkpFull.days
}
if($howOldBkpFull -gt '7' -or $lstfull -eq "Alert!"){$bgfcolor = "purple"}else{$bgfcolor = ""}
$lstinc = $Database.LastIncrementalBackup
if ( $lstinc -eq $null){ $lstinc = "Alert!"}else{
$lstinc = $lstinc.ToString('dd/MM/yyyy')
$lastIncBackup = $Database.LastIncrementalBackup; $currentDate = Get-Date
$howOldIncFull = $currentDate – $lastIncBackup
$howOldIncFull = $howOldIncFull.days
}
if($howOldIncFull -gt '1' -or $lstinc -eq "Alert!"){$bgicolor = "purple"}else{$bgicolor = ""}
$bgcolor = "white"
if($dbsize -gt '550' -and $svcState -lt '20'){$bgcolor = "yellow"}
if($dbsize -gt '600' -and $svcState -lt '15'){$bgcolor = "orange"}
if($dbsize -gt '650' -and $svcState -lt '10'){$bgcolor = "red"}
Add-Content $whitespace "<tr bgcolor= '$bgcolor'>"
Add-Content $whitespace "<td align=center>$machineName</td>"
20643
45954
230
false
How to rename a file using get-childitem
Hello,
I am new to this website and powershell.
I would like to know how I can rename a file using the get-childitem. For example, I would like to go from ABC.BAK to 123.BAK. The problem that I am having is that the names of the files are rather long (ServerName_database_full_20150125_185957.bak) and constantly changing. Is there a way that I can tell Powershell to look in the folder get the file and rename it to what I want.
I tried several ways with no luck, the only way that I was able to change the name using Powershell was to use the following.
rename-item -path i:testServerName_database_full_20150125_185957.bak -newname database.bak
However this will not work for me because the original file names are always changing. My goal is to automate this so that the files are rename to what I want.
]]>