Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

dynamicOpenLogFile

Publié le par damcuvelier

$Global:GlobLogfile = "c:\chemin\vers\le\fichier\de\log"

function isLogFileOpen{
    param($logfile)
    $erroractionpreference = 'SilentlyContinue'
    $ici = (get-location).path
    set-location $here
    $username = $env:username
    if(!$logfile){$logfile = $Global:GlobLogfile}
    $result = $false

    Get-WmiObject Win32_Process | ForEach-Object {
        $process = $_
        $name = $process.Name
        $cmdline = $process.CommandLine
        $owner = $process.GetOwner().User
        if ($cmdline -and ($cmdline.ToUpper() -match [regex]::Escape($logfile.ToUpper()))) {$result = $true}
    }

set-location $ici
return $result
}

function openlogfile($LogFile){
    $erroractionpreference = 'SilentlyContinue'
    $ici = (get-location).path
    set-location $here
    if(!$logfile){$logfile = $Global:GlobLogfile}
    $LogFileOpen = isLogFileOpen
    if ($LogFileOpen) {write-host ''}else{
        set-location $ici
        cmd /c "start c:\windows\system32\cmtrace.exe $logfile"
    }
set-location $ici
}


openlogfile

Commenter cet article