Archive for the ‘Scripts’ Category

Search and replace text in file

August 5, 2014

1. VBScript

‘Usage: cscript SR.vbs readme.txt  Robert Julias

Const ForReading = 1
Const ForWriting = 2

strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)

Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.Write strNewText
objFile.Close

 

2. PowersHELL (Ex 1)

cat readme.txt | %{$_ -replace “oldtext”,”newtext”}

 

3. PowersHELL (Ex 2)

Get-ChildItem -exclude *.bak | Where-Object {$_.Attributes -ne “Directory”} |
ForEach-Object { Copy-Item $_ “$($_).bak”; (Get-Content $_) -replace
“oldtext”,”newtext” | Set-Content -path $_ }

 

4. PowersHELL (Ex 3)

param( [string]$Find, [string]$Replace, [string]$Path )
gci -Path $Path -recurse | foreach{ (gc $_) -replace $Find,$Replace | sc $_ }

./sr.ps1 oldtext newtext *.txt

 

5. PowersHELL (Ex 4)

(Get-Content C:\Scripts\readme.txt) |
Foreach-Object {$_ -replace “\*”, “@”} |
Set-Content C:\Scripts\readme_new.txt

Advertisements

How To Create System Backup Image In Windows 7 and 8.1

August 17, 2013

You may create a system backup image after installing all device drivers, favourite software and optimizing Windows. The backup image file is useful when there is a hard drive failure or when you need a fresh working system.

1. Connect your USB drive

2. Run Command Prompt as administrator

3.  Type,

wbAdmin start backup -backupTarget:H: -include:C: -allCritical –quiet

(Replace “H” with your USB drive and “C” is the Windows OS installation drive)

4. Once done, you’ll see “The backup operation successfully completed” message.

(May take hours depend on applications installed)

 

Protected: Effectively using Robocopy

December 4, 2012

This content is password protected. To view it please enter your password below:

About WMIC

October 23, 2012

Get Model of computer,

wmic csproduct list brief /format:list

|–  wmic csproduct get name

OR

wmic computersystem list brief /format:list

|–  wmic computersystem get model

 

Get Serial of computer,

wmic bios list brief /format:list

|–  wmic bios get serialnumber

How to recursive list only .doc files but ignore .docx files

April 16, 2012

forfiles /s /m *.doc /c “cmd /c echo @file”
forfiles /s /m *.doc /c “cmd /c echo @path”

To compact files,
forfiles /s /m *.doc /c “cmd /c compact /c @file”

To uncompact files,
forfiles /s /m *.doc /c “cmd /c compact /u @file”

[win8]

search for files created TODAY :

FORFILES /s /D 0 /m *.doc /C “cmd /c echo @fname @path @fdate @fsize” 2>nul

Default processing behavior for Group Policy scripts

October 23, 2010

Microsoft changed the default behavior of Group Policy startup and logon scripts processing from synchronous to asynchronous starting with Windows Vista and Windows Server 2008. It’s still the same in Windows 7 and Windows Server 2008 R2.

Asynchronous scripts processing is when computer startup scripts no longer wait for the previous script to complete before starting the next startup script. Versions of Windows prior to Windows Vista defaulted to synchronous processing.

You need to configure the Run startup scripts asynchronously policy setting to disabled to force computer startup scripts to process synchronously, which is the default behavior prior to Windows 7 and Windows Vista. 

User Logoff and Computer Shutdown Group Policy Scripts always process synchronously.

Remove orphaned cached Windows Installer Data files

November 13, 2009

Download “Windows Installer Clean Up” utility

There are two versions of MSIZAP.EXE:

MsiZapA.exe (for use in Windows 95, Windows 98 and Windows ME)

MsiZapU.exe (for use in Windows NT, Windows 2000, Windows XP, and Windows Server 2003).

The appropriate executable should be renamed MsiZap.exe.

To run msizap, login to the machine as an administrative user and launch a command window. Navigate to the directory that contains msizap.exe, then type the following command:

msizap !G

G = remove orphaned cached Windows Installer data files (for all users)
! = force ‘yes’ response to any prompt

The TechNet Script Center Gallery

August 23, 2009

The TechNet Script Center Gallery contains sample scripts that are designed to run on Windows Server 2008, Windows Server 2003, Windows Vista, Windows XP, and Windows 2000.

Delete zero byte files

February 5, 2009

REM XP tested only
@echo off
for /f “tokens=* delims=” %%F in (‘dir /s/b/a-d TEMP’) do (
if 0 equ %%~zF del “%%F”
)

WMI Diagnosis Tool General Questions

August 18, 2008

From (WMI) Team Blog