From d0adf96a83da1db8700c0ef248934ff689f473ce Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 30 Apr 2017 20:14:00 +0200 Subject: [PATCH] Additional script modifications --- src/ci/scripts/cleanup.bat | 4 +++ src/ci/scripts/cleanup.ps1 | 53 +++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 src/ci/scripts/cleanup.bat diff --git a/src/ci/scripts/cleanup.bat b/src/ci/scripts/cleanup.bat new file mode 100644 index 000000000..2e74bf777 --- /dev/null +++ b/src/ci/scripts/cleanup.bat @@ -0,0 +1,4 @@ +@echo off +SET runpath=%~dp0 + +PowerShell.exe -NonInteractive -ExecutionPolicy bypass -File %runpath%src\ci\scripts\cleanup.ps1 %* diff --git a/src/ci/scripts/cleanup.ps1 b/src/ci/scripts/cleanup.ps1 index 6ffd69465..cb3361fb8 100644 --- a/src/ci/scripts/cleanup.ps1 +++ b/src/ci/scripts/cleanup.ps1 @@ -1,30 +1,36 @@ <# - Powershell script for cleaning up remaining processes on the CI servers + Powershell script for cleaning up remaining browser and selenium server processes on the CI servers #> +param ( + [switch]$Verbose = $False, + [String[]]$Browsers = @("firefox.exe","iexplore.exe","chrome.exe") +) + $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name Write-Output "User: $currentUser" -$currentUser = "$env:UserDomain\$env:UserName" -Write-Output "User2: $currentUser" - -Get-Process | Get-Member -$View = @( - @{l='Handles';e={$_.HandleCount}}, - @{l='NPM(K)';e={ (Get-Process -Id $_.ProcessId).NonpagedSystemMemorySize/1KB -as [int]}}, - @{l='PM(K)';e={ $_.PrivatePageCount/1KB -as [int]}}, - @{l='WS(K)';e={ $_.WorkingSetSize/1KB -as [int]}}, - @{l='VM(M)';e={ $_.VirtualSize/1mB -as [int]}}, - @{l='CPU(s)';e={ (Get-Process -Id $_.ProcessId).CPU -as [int]}}, - @{l='Id';e={ $_.ProcessId}}, - 'UserName' - @{l='ProcessName';e={ $_.ProcessName}} -) -Get-WmiObject Win32_Process | % { $_ | - Add-Member -MemberType ScriptProperty -Name UserName -Value { - '{0}\{1}' -f $this.GetOwner().Domain,$this.GetOwner().User - } -Force -PassThru -} +if ($Verbose) +{ + Get-Process | Get-Member + + $View = @( + @{l='Handles';e={$_.HandleCount}}, + @{l='NPM(K)';e={ (Get-Process -Id $_.ProcessId).NonpagedSystemMemorySize/1KB -as [int]}}, + @{l='PM(K)';e={ $_.PrivatePageCount/1KB -as [int]}}, + @{l='WS(K)';e={ $_.WorkingSetSize/1KB -as [int]}}, + @{l='VM(M)';e={ $_.VirtualSize/1mB -as [int]}}, + @{l='CPU(s)';e={ (Get-Process -Id $_.ProcessId).CPU -as [int]}}, + @{l='Id';e={ $_.ProcessId}}, + 'UserName' + @{l='ProcessName';e={ $_.ProcessName}} + ) + Get-WmiObject Win32_Process | % { $_ | + Add-Member -MemberType ScriptProperty -Name UserName -Value { + '{0}\{1}' -f $this.GetOwner().Domain,$this.GetOwner().User + } -Force -PassThru + } +} @@ -41,10 +47,9 @@ foreach($proc in $processes) } } -Write-Output "Filter: name = '$procName'" -$browsers = "firefox.exe","iexplore.exe","chrome.exe" -foreach ($procName in $browsers) +foreach ($procName in $Browsers) { + Write-Output "Filter: name = '$procName'" $processes = Get-WmiObject Win32_Process -Filter "name = '$procName'" | Where-Object {$_.GetOwner().User -eq $currentUser } foreach($proc in $processes) { -- 2.39.5