Command Line

Configure The Windows Services Recovery Options From Command Line

The command will configure the recovery options for a given service as:

  • First Failure: Restart the Service
  • Second Failure: Restart the Service
  • Subsequent failures: Take No Action (this is set to “take No Action” to avoid infinite restart attempts)
  • Restart Fail Count After: 1 Day
  • Restart Service After: 1 minute

2014-11-02 14_08_32-Remote Desktop Manager [Quick connect - EGCTRX01DR] - Trial version expire in 5

SC failure <Service Name> actions= restart/60000/restart/60000/""/60000 reset= 86400

Example for Message Queuing service:

SC failure MSMQ actions= restart/60000/restart/60000/""/60000 reset= 86400

One-Liner: Move Multible Users to a Specific OU (Powershell)

This PowerShell command will read the users’ alias from a text file, and will move them to a specific OU.

Preparation:
  • On you domain controller, create a text file at C:\MoveUsers\Users.txt
  • In Users.txt add users aliases one per each line.
  • Get the DN for the destination OU, one easy common way, is to open ADSI Edit, expand the tree on the left till you reach the desired OU –> in the properties of the OU you will get the OU DN.
  • Open PowerShell and import the Active Directory Module:
Import-Module ActiveDirectory
The Command:
Get-Content C:\MoveUsers\Users.txt | Foreach{Get-ADUser $_ | Move-ADObject -TargetPath "OU=HR Users,OU=Users,DC=Masry,DC=Lab"}

Replace OU=HR Users,OU=Users,DC=Masry,DC=Lab with your OU DN obtained previously.

How to Isolate Forefront Protection For Exchange While Troubleshooting Emails Related Issues

It’s likely for while troubleshooting an emails related issues like some Exchange services are not starting, or there’s a delay in the messages processing… etc, that you will be thinking to isolate the issue to perform your root cause analysis.

One thing you may consider is to temporarily disable the integration of the Exchange Services and Forefront Protection for Exchange 2010 (FPE 2010) or the old Forefront Security for Exchange FSE.

A specific utility called Fscutility.exe that’s available in the FPE installation directory (as well as FSE) can help you to easily perform this action as shown below:

1- Open the command prompt (cmd.exe)

2- Move to the Forefront Protection for Exchange installation directory, for Example:

CD “C:\Program Files (x86)\Microsoft Forefront Protection for Exchange Server”

3- To check the current integration status, run this command:

Fscutility /status

4- To Disable the Integration:

Fscutility /disable

5- To Re-Enable the integration:

Fscutility /enable

Note:

I found that this utility parameters are case sensitive, so Fscutility /disable is correct, but Fscutility /Disable will not work.

Script To Monitor Internet Connectivity and Automatically Reset Wireless Connection

Ehlo,

So, We have a non stable Wireless access point, non stable Internet connection!

and at times we will get that yellow triangle with the exclamation mark on the WIFI connection on our PCs, and the only way to restore the connection is to Disconnect/and reconnect to the wireless AP.

I wrote this batch to automate this process, It could be written by another ways, but I find this simple and straight forward.

What the batch file do is:

Ping a Public IP –> If failed –> Try again after 1 Minute –> If still failed –> Disconnect from the wireless network –> Wait for 1 Minute –> Connect to the wireless network –> Start over again.

Prerequisites:

1- Name your Wireless card as WAN (or edit the batch to reflect your wireless “card name”).

2- replace YourWirelessSSID in the batch with your actual wireless network name (SSID).

3- If required,  make the batch starts with your windows startup, so it runs automatically.

The Batch:

@Echo off
:Start
CLS

Rem ####################Ping Check#####################

Ping 4.2.2.2 |find "TTL=" && GOTO Start
Ping -n 60 127.0.0.1 >nul
Ping 4.2.2.2 |find "TTL=" && GOTO Start

Rem ###########Reset The Wireless Network##############

netsh wlan disconnect interface=WAN
Ping -n 60 127.0.0.1 >nul
Echo.
netsh wlan connect ssid=YourWirelessSSID name=YourWirelessSSID interface=WAN
Ping -n 10 127.0.0.1 >nul

GOTO Start

 

Note: tested on Win 7

ROBOCOPY

Robocopy, or "Robust File Copy", is a command-line directory replication command. It has been available as part of the Windows Resource Kit starting with Windows NT 4.0, and was introduced as a standard feature of Windows Vista, Windows 7 and Windows Server 2008.

 

Do not include a trailing backslash

 

Good Examples: [1]

 image

Robocopy C:\InstallationMedia "D:\Backup of InstallationMedia" /copyall /E

Copy directory contents of ​foo​ to ​bar​ (including file data, attributes and timestamps), recursively with empty directories (/E):

 robocopy C:\foo C:\bar /E

Copy directory recursively (/E), and copy all file information (/COPYALL, equivalent to /COPY:DATSOU, D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=aUditing info), do not retry locked files (/R:0), preserve original directories’ Timestamps (/DCOPY:T – requires version XP026 or later):

 robocopy C:\foo C:\bar /COPYALL /E /R:0 /DCOPY:T 

Mirror foo to bar, destroying any files in bar that are not present in foo (/MIR), copy files in restartable mode (/Z) in case network connection is lost:

 robocopy C:\foo \\backupserver\bar /MIR /Z

 

Copy files from one server to another (auto skip files already in the destination)

ROBOCOPY \\Server1\reports \\Server2\backup *.doc /S

List files over 32 MBytes in size:

ROBOCOPY C:\work /MAX:33554432 /L

Move files over 14 days old: (note the MOVE option will fail if any files are open and locked.)

ROBOCOPY C:\work C:\destination /move /minage:14

Backup a Server

The script below copies data from FileServ1 to FileServ2, the destination holds a full mirror along with file security info. When run regularly to synchronize the source and destination, robocopy will only copy those files that have changed (change in time stamp or size.)

@ECHO OFF

SETLOCAL

SET _source=\\FileServ1\e$\users

SET _dest=\\FileServ2\e$\BackupUsers

SET _what=/COPYALL /B /SEC /MIR

:: /COPYALL :: COPY ALL file info

:: /B :: copy files in Backup mode.

:: /SEC :: copy files with SECurity

:: /MIR :: MIRror a directory tree

SET _options=/R:0 /W:0 /LOG:MyLogfile.txt /NFL /NDL

:: /R:n :: number of Retries

:: /W:n :: Wait time between retries

:: /LOG :: Output log file

:: /NFL :: No file logging

:: /NDL :: No dir logging

ROBOCOPY %_source% %_dest% %_what% %_options%

Run two robocopy jobs at the same time with START /Min

Start /Min "Job one" Robocopy \\FileServA\C$\Database1 \\FileServeBackupA\c$\BackupsStart /Min "Job two" Robocopy \\FileServB\C$\Database2 \\FileServeBackupB\c$\Backups

 

How to Use Robocopy to copy security information without copying any file data[2]

By default, Robocopy copies file data for any file that appears to be older, newer, or changed. You can use the /secfix parameter when you run the Robocopy command line to copy only security information for existing files. Additionally, you must use the /xo parameter, the /xn parameter, and the /xc parameter when you run the Robocopy command with the /secfix parameter, for example:

robocopy source destination /secfix /xo /xn /xc

If you run this command line, Robocopy refreshes only the security information for existing files; it does not copy any file data.

If you want to maintain the destination folder as an exact mirror of the source folder, you must run Robocopy with the appropriate parameters to refresh only the file security information, and then run the Robocopy command without using the /xo, the /xn, or the /xc parameters. After you do so, the file data content is consistent between the source file and the destination file.

For definitions of Robocopy terms that are used in this article and for information about other Robocopy functions and features, see Robocopy.doc.

 

Download Robocopy GUI