Answer the question
In order to leave comments, you need to log in
The script doesn't work. How to run a script without waiting for it to complete?
Hello everyone)
It is required to write a script that, in case of a change in the configuration file, wrote LOG. At the same time, it must be executed by a separate process without waiting for the end of the cycle.
$ScriptBlock = {
while($true){
$microsipini="$Env:USERPROFILE\AppData\Roaming\MicroSIP\microsip.ini" #В каком файле нужно проверять стоку
$namelog=$env:UserName #Название файла
$folderlog='\\fs01\LOG\' #Куда сохранять лог
$datatime=Get-Date #Переменная дата/время
$ideallineini = 'autoAnswer=' #Эталонное значение
$textp='Строка изменена:' #Текст в логе
$lineini = Get-Content -Path $microsipini | Select-String -Pattern 'autoAnswer=' #Присвоение переменной значение определённой строки (Например autoAnswer=)
if( $lineini -notlike $ideallineini ) { #Сравнения эталонного значения с строкой в файле
Write-Output $textp$datatime','$env:UserName | Out-File $folderlog$namelog'.log' -Append #Запись лога в случае несовпадения(-notlike)/совпадения(-like) строк
}
Start-Sleep 3 #Таймер цикла.Как часто команда будет обрабатываться.
}
}
Start-Job -ScriptBlock $ScriptBlock
powershell C:\microsip.ps1
Answer the question
In order to leave comments, you need to log in
It's not very clear what you mean by "doesn't work"
but in any case, you do a Start-Job and this is where your script ends
and Wait-Job is nowhere to be found
In a separate script, you don't need a job
update at all:
And if, in essence, the task , you need to look towards FileSystemWatcher
https://powershell.one/tricks/filesystem/filesyste...
https://devblogs.microsoft.com/powershell-communit...
https://stackoverflow.com/questions/29066742 /watch...
instead of loading the computer with unnecessary work on cyclic reading of files
a lot of coding if you do it yourself, but there is a script directly from that page Script
copy the DOM menu structure from the site using your link, connect the script indicated above, write
$(document).ready(function () {
ko.applyBindings(wikiNavViewModel, $('[data-id="wiki"]')[0]);
nav_slide.init();
wikiNavViewModel.show_menu(true);
$('[data-id="wiki"]').css('visibility', 'visible');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question