Skip to content

Instantly share code, notes, and snippets.

@echo off
setlocal
set "SERVICE_NAME=service_name"
:: Check if the service exists using PowerShell
for /f "delims=" %%i in ('powershell -Command "$service = Get-Service -Name '%SERVICE_NAME%' -ErrorAction SilentlyContinue; if ($null -eq $service) { Write-Output 'NotExists' } else { Write-Output 'Exists' }"') do set "SERVICE_EXISTS=%%i"
if "%SERVICE_EXISTS%"=="NotExists" (
echo The service %SERVICE_NAME% does not exist.
# Define variables
$searchString = "Error" # The string to search for in event logs
$since = (Get-Date).AddDays(-1) # Only events from the last day
$outputFile = "C:\Path\To\Your\events.csv" # Specify your output file path
# Prepare the CSV file
if (Test-Path $outputFile) {
Remove-Item $outputFile -Force # Delete existing file if it exists
}
@brovish
brovish / search_info_file_v3.cmd
Created February 7, 2024 10:46
search_info_file_v3.cmd c:\temp file.ini string
@echo off
setlocal EnableDelayedExpansion
if "%~3"=="" (
echo Incorrect usage. The correct usage is: %~nx0 "Search Directory" "Filename Pattern" "Search String"
exit /b
)
@brovish
brovish / search_pids_in_logs.cmd
Created February 6, 2024 14:26
search word in files
@echo off
setlocal EnableDelayedExpansion
set "FOLDER_PATH=D:\Software\FAF\Logs\lex"
set "TEMP_FILE=%TEMP%\temp_results.txt"
if exist "%TEMP_FILE%" del "%TEMP_FILE%"
<#
.SYNOPSIS
Collect-ServerInfo.ps1 - PowerShell script to collect information about Windows servers
.DESCRIPTION
This PowerShell script runs a series of WMI and other queries to collect information
about Windows servers.
.OUTPUTS
Each server's results are output to HTML.
@brovish
brovish / fn_ConsecutiveNumbers.sql
Created June 1, 2023 13:09
from stackoverflow
CREATE FUNCTION [dbo].[fn_ConsecutiveNumbers]
(
@start int,
@end int
) RETURNS TABLE
RETURN
select
x268435456.X
| x16777216.X
--To search all columns of all tables in Pubs database for the keyword "Computer"
EXEC SearchAllTables 'Computer'
GO
Here is the complete stored procedure code:
CREATE PROC SearchAllTables
(
@SearchStr nvarchar(100)
@brovish
brovish / oracle_recreate_schema.sql
Created December 29, 2022 07:20
Oracle script to recreate the schema (delete if there is a connection user, drop schema, recreate) DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp diagram as parameter, password p240580 you can expand it, for example, a password, so that it would be an optional parameter
WHENEVER SQLERROR EXIT SQL.SQLCODE
SET ECHO ON
/
set autocommit on
DEF username = &1
--DEF pwd = &2
/
DEF default_ts = users
/
@brovish
brovish / wget-exit-codes.txt
Created August 27, 2022 05:39 — forked from cosimo/wget-exit-codes.txt
wget exit codes
This is the list of exit codes for wget:
0 No problems occurred
1 Generic error code
2 Parse error — for instance, when parsing command-line options, the .wgetrc or .netrc…
3 File I/O error
4 Network failure
5 SSL verification failure
6 Username/password authentication failure
7 Protocol errors
@brovish
brovish / Index Defragmantion Script Template.sql
Created June 13, 2022 08:49
Index Defragmantion Script Template from Expert Performance Indexing in SQL Server
--Listing 9-27. Index Defragmantion Script Template
DECLARE @MaxFragmentation TINYINT=30
,@MinimumPages SMALLINT=1000
,@SQL nvarchar(max)
,@ObjectName NVARCHAR(300)
,@IndexName NVARCHAR(300)
,@CurrentFragmentation DECIMAL(9, 6)
DECLARE @FragmentationState TABLE
(
SchemaName SYSNAME