Skip to content

Commit ca10c47

Browse files
authored
Implementing Enable / Disable log to file function
1 parent 28a29cf commit ca10c47

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

RAM-Logger.ps1

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ $Lang = {
8585
[string]$l33 = "Переконайтеся, що WinRM запущено та правильно налаштовано."
8686
[string]$l34 = "Для моніторингу localhost виберіть ""Моніторинг поточного ПК"" в меню програми."
8787
[string]$l35 = "Створення CIM сесії для"
88+
[string]$l36 = "Увімкнути запис логу до файлу? (1 - Так | 0 - Ні)"
8889
}
8990
else{.$Lang}
9091
.$About
@@ -120,6 +121,8 @@ $Startlocallog = {
120121
catch {.$Invvalue}
121122
$freq = [math]::Round($freq, 0)
122123
if($freq -lt 1){.$Invvalue}
124+
$tofile = Read-Host "$l35"
125+
if(($tofile -ne 1) -and ($tofile -ne 0)){.$Invvalue}
123126
Write-Host "`n"
124127
$computerlog = "localhost"
125128
Write-Host "$l25 $computerlog ..."
@@ -190,7 +193,9 @@ $Prelog = {
190193
Write-Host "`n"
191194
$startmsg = "$l14"
192195
Write-Host "$startmsg"
193-
$startmsg | Out-File -filepath $logpath -Append String
196+
if($tofile -eq 1){
197+
$startmsg | Out-File -filepath $logpath -Append String
198+
}
194199
$mainram = Get-CimInstance win32_operatingsystem -CimSession $session
195200
[decimal]$total = $mainram.TotalVisibleMemorySize/1024/1024
196201
$xtotal = $total | % {$_.ToString("0.000")}
@@ -217,7 +222,9 @@ $Startlog = {
217222
$xmaxusedp = $maxusedp | % {$_.ToString("000")}
218223
$log = "[$timestamp | $computerlog] Current: $xcrtuseds Gb / $xtotal Gb ($xcrtusedp%) | Min: $xminuseds Gb ($xminusedp%) | Max: $xmaxuseds Gb ($xmaxusedp%)"
219224
Write-Host "$log"
220-
$log | Out-File -filepath $logpath -Append String
225+
if($tofile -eq 1){
226+
$log | Out-File -filepath $logpath -Append String
227+
}
221228
$timeloop = $freq
222229
.$Loopmain
223230
}
@@ -233,9 +240,13 @@ $Loopmain = {
233240
$Stoplog = {
234241
$stopmsg = "$l15"
235242
Write-Host "$stopmsg"
236-
$stopmsg | Out-File -filepath $logpath -Append String
243+
if($tofile -eq 1){
244+
$stopmsg | Out-File -filepath $logpath -Append String
245+
}
237246
$lbreak = "`n"
238-
$lbreak | Out-File -filepath $logpath -Append String
247+
if($tofile -eq 1){
248+
$lbreak | Out-File -filepath $logpath -Append String
249+
}
239250
Write-Host "`n"
240251
Write-Host "$l16 $logpath"
241252
.$Askadv

0 commit comments

Comments
 (0)