Syed Jahanzaib Personal Blog to Share Knowledge !

June 19, 2014

SAN attached windows 2008 hangs on boot

Filed under: IBM Related, Microsoft Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 9:37 AM

Just for reference purpose:

Recently I was testing some disaster recovery scenario of restoring Server A to Server B with identical hardware using Symantec Backup EXEC 2014 Simplified Disaster Recovery [SDR]CD. The hardware specs were as follows …

IBM Xseries 3650 M4, with RAID1
Dual Q.Logic Fiber Channel cards Mode: QLE2560 connected with two FC switches for multi path and failover
32 GB RAM,
IBM v3700 storewize SAN Storage

The restore went fine , system boot fine for the first time with everything intact, but when I rebooted it again , it failed to boot and shows only cursor blinking,  As showed in the image below …

123

I tried to boot it several times but with no results. I then removed the FC cables from the server’s Qlogic FC cards, and this time windows booted fine.

Solution:

I started the server without FC cables attached, then I removed the Windows MPIO features from ADD REMOVE FEATURES, and rebooted again with FC cables attached, and this time it works fine but showed duplicate SAN partitions. Then I applied IBM’s SSDM MPIO driver (MPIO_Win2008_x64_SDDDSM_64_2434-4_130816 for v3700 storewize)  and everything went fine 🙂

You may also want to read the IBM’s article.
http://www-947.ibm.com/support/entry/portal/docdisplay?lndocid=migr-5081613

 

.

Regard’s
Syed Jahanzaib

March 14, 2014

WSUS Clients Getting Error Code 800b0001

Filed under: Microsoft Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 10:00 AM

In our company, we have a Windows 2003 base WSUS 3.0 with SP2 (Windows Update) server which is responsible to update all local clients and server base windows including 2000 / 2003 / 2008 / XP / W7  versions.

Recently we added four new IBM base servers with Windows 2008 R2 but unable to update, showing following error …

wsus-error-b0001

.

After doing few hours R&D, I found out that this is usually due to the WSUS Update Agent on the client being updated, but the WSUS server itself also needs to be upgraded to then allow communication with the newer agent. After installing SP2, you *MUST* also apply a later update “Update for Windows Server Update Services 3.0 SP2 (KB2720211

http://www.microsoft.com/en-us/download/details.aspx?id=29998

There was no need to reboot the server last time I ran this process, and the clients were able to communicate and obtain updates correctly.

.

Regard’s
Syed Jahanzaib

October 8, 2013

PPPoE Dialer via DOS Batch File

Filed under: Microsoft Related — Tags: , , , — Syed Jahanzaib / Pinochio~:) @ 1:53 PM

Changelog:

8th Oct , 2013 9:30pm : Entry added  to create network profile folder if not already there (usually on fresh win7)
9th Oct , 2013 01:45pm : Entry added  to create new phonbook profile, it will not overwrite or delete previous one 🙂

Following is a simple and quickest method to create pppoe dialer using MSDOS batch file made for Windows 7, which create a new rasphone profile for PPPoE Dialer. Usually this sort of work is done using VB , or VB/VC# .NET with Dotras type programming languages which does the job nicely with lots of options and fancy look menus etc, but due to my limited knowledge towards programming, I decided to go with my traditional CLI method. I created this batch program in a very short time without much googling.

Phonebook Location to store profiles (new and old)

%userprofile%\AppData\Roaming\Microsoft\Network\Connections\Pbk\

This is just an example, you can modify at as per your requirements , The issue i faced while adding multiple lines was white space at the end, and if there are additional white spaces in the file , rasphone will not detect the new entry. therefore I later used algorithm to remove white spaces.

Any suggestion to improve the method will be highly appreciable . . . Please psot your comment if this batch file is working ok for you . . .

Let’s Start.

Create a new batch file like

notepad c:\dialer.bat

Paste following data and save.

@echo off
rem
rem #########################################
rem ### PPPoE Dialer Script for Windows 7
rem ### Syed Jahanzaib / aacable@hotmail.com
rem ### http://aacablw.wordpress.com
rem #########################################

rem ### Creating pppoe profile in a temporarily text file
echo. 2>  c:\rstemp.txt
echo [AA_PPPoE_Dialer] >> c:\rstemp.txt
echo Encoding=1 >> c:\rstemp.txt
echo PBVersion=1 >> c:\rstemp.txt
echo Type=5  >> c:\rstemp.txt
echo AutoLogon=0 >> c:\rstemp.txt
echo UseRasCredentials=0 >> c:\rstemp.txt
echo LowDateTime=-582619296 >> c:\rstemp.txt
echo HighDateTime=30327625 >> c:\rstemp.txt
echo DialParamsUID=6326979 >> c:\rstemp.txt
echo Guid=359A05BF4C146640949F56383A0F18F5 >> c:\rstemp.txt
echo VpnStrategy=0 >> c:\rstemp.txt
echo ExcludedProtocols=0 >> c:\rstemp.txt
echo LcpExtensions=1 >> c:\rstemp.txt
echo DataEncryption=8 >> c:\rstemp.txt
echo SwCompression=0 >> c:\rstemp.txt
echo NegotiateMultilinkAlways=0 >> c:\rstemp.txt
echo SkipDoubleDialDialog=0 >> c:\rstemp.txt
echo DialMode=0 >> c:\rstemp.txt
echo OverridePref=15 >> c:\rstemp.txt
echo RedialAttempts=3 >> c:\rstemp.txt
echo RedialSeconds=60 >> c:\rstemp.txt
echo IdleDisconnectSeconds=0 >> c:\rstemp.txt
echo RedialOnLinkFailure=1 >> c:\rstemp.txt
echo CallbackMode=0 >> c:\rstemp.txt
echo CustomDialDll= >> c:\rstemp.txt
echo CustomDialFunc= >> c:\rstemp.txt
echo CustomRasDialDll= >> c:\rstemp.txt
echo ForceSecureCompartment=0 >> c:\rstemp.txt
echo DisableIKENameEkuCheck=0 >> c:\rstemp.txt
echo AuthenticateServer=0 >> c:\rstemp.txt
echo ShareMsFilePrint=0 >> c:\rstemp.txt
echo BindMsNetClient=0 >> c:\rstemp.txt
echo SharedPhoneNumbers=0 >> c:\rstemp.txt
echo GlobalDeviceSettings=0 >> c:\rstemp.txt
echo PrerequisiteEntry= >> c:\rstemp.txt
echo PrerequisitePbk= >> c:\rstemp.txt
echo PreferredPort=PPPoE4-0 >> c:\rstemp.txt
echo PreferredDevice=WAN Miniport (PPPOE) >> c:\rstemp.txt
echo PreferredBps=0 >> c:\rstemp.txt
echo PreferredHwFlow=0 >> c:\rstemp.txt
echo PreferredProtocol=0 >> c:\rstemp.txt
echo PreferredCompression=0 >> c:\rstemp.txt
echo PreferredSpeaker=0 >> c:\rstemp.txt
echo PreferredMdmProtocol=0 >> c:\rstemp.txt
echo PreviewUserPw=1 >> c:\rstemp.txt
echo PreviewDomain=0 >> c:\rstemp.txt
echo PreviewPhoneNumber=0 >> c:\rstemp.txt
echo ShowDialingProgress=1 >> c:\rstemp.txt
echo ShowMonitorIconInTaskBar=1 >> c:\rstemp.txt
echo CustomAuthKey=0 >> c:\rstemp.txt
echo AuthRestrictions=552 >> c:\rstemp.txt
echo IpPrioritizeRemote=1 >> c:\rstemp.txt
echo IpInterfaceMetric=0 >> c:\rstemp.txt
echo IpHeaderCompression=0 >> c:\rstemp.txt
echo IpAddress=0.0.0.0 >> c:\rstemp.txt
echo IpDnsAddress=0.0.0.0 >> c:\rstemp.txt
echo IpDns2Address=0.0.0.0 >> c:\rstemp.txt
echo IpWinsAddress=0.0.0.0 >> c:\rstemp.txt
echo IpWins2Address=0.0.0.0 >> c:\rstemp.txt
echo IpAssign=1 >> c:\rstemp.txt
echo IpNameAssign=1 >> c:\rstemp.txt
echo IpDnsFlags=0 >> c:\rstemp.txt
echo IpNBTFlags=0 >> c:\rstemp.txt
echo TcpWindowSize=0 >> c:\rstemp.txt
echo UseFlags=3 >> c:\rstemp.txt
echo IpSecFlags=0 >> c:\rstemp.txt
echo IpDnsSuffix= >> c:\rstemp.txt
echo Ipv6Assign=1 >> c:\rstemp.txt
echo Ipv6Address=:: >> c:\rstemp.txt
echo Ipv6PrefixLength=0 >> c:\rstemp.txt
echo Ipv6PrioritizeRemote=1 >> c:\rstemp.txt
echo Ipv6InterfaceMetric=0 >> c:\rstemp.txt
echo Ipv6NameAssign=1 >> c:\rstemp.txt
echo Ipv6DnsAddress=:: >> c:\rstemp.txt
echo Ipv6Dns2Address=:: >> c:\rstemp.txt
echo Ipv6Prefix=0000000000000000 >> c:\rstemp.txt
echo Ipv6InterfaceId=0000000000000000 >> c:\rstemp.txt
echo DisableClassBasedDefaultRoute=0 >> c:\rstemp.txt
echo DisableMobility=0 >> c:\rstemp.txt
echo NetworkOutageTime=0 >> c:\rstemp.txt
echo ProvisionType=0 >> c:\rstemp.txt
echo PreSharedKey= >> c:\rstemp.txt

echo NETCOMPONENTS= >> c:\rstemp.txt
echo ms_msclient=0 >> c:\rstemp.txt
echo ms_server=0 >> c:\rstemp.txt

echo MEDIA=rastapi >> c:\rstemp.txt
echo Port=PPPoE4-0 >> c:\rstemp.txt
echo Device=WAN Miniport (PPPOE) >> c:\rstemp.txt

echo DEVICE=PPPoE >> c:\rstemp.txt
echo LastSelectedPhone=0 >> c:\rstemp.txt
echo PromoteAlternates=0 >> c:\rstemp.txt
echo TryNextAlternateOnFail=1 >> c:\rstemp.txt

rem ### Removing white spaces so that it can be readable by phone book /zaib
rem echo. 2>  c:\rscompile.bat
rem if [%1]==[] then echo File name missing & goto :EOF >>
(for /f "tokens=1" %%a in (rstemp.txt) do echo %%a) > %~n1aa-rasphone.pbk

rem ### Location for rasphone.pbk [just for reference] /zaib
rem %userprofile%\AppData\Roaming\Microsoft\Network\Connections\Pbk\

rem ### Creating Network Profile Folder to store dialer profile, if its not there already
mkdir %userprofile%\AppData\Roaming\Microsoft\Network
mkdir %userprofile%\AppData\Roaming\Microsoft\Network\Connections
mkdir %userprofile%\AppData\Roaming\Microsoft\Network\Connections\pbk
cls
rem Copy new rasphone.pbk to user network profile /zaib
rem cd %userprofile%\AppData\Roaming\Microsoft\Network\Connections\Pbk\
rem ren rasphone.pbk rasphone.pbk.old
copy c:\aa-rasphone.pbk %userprofile%\AppData\Roaming\Microsoft\Network\Connections\Pbk\

rem ### Create Network Connection Center Icon on Desktop /zaib
rem ### I coulnd't found a way to create shortcut of dialer on desktop, someone please suggest
set linkName=AA-Network Connections
set linkPath=%userprofile%\desktop
set program=C:\WINDOWS\SYSTEM32\ncpa.cpl
set workDir=C:\WINDOWS\system32
set iconfile=%SystemRoot%\system32\SHELL32.dll
set icon=-18
set windowStyle=2
echo Set oWS = WScript.CreateObject("WScript.Shell") > temp.vbs
echo sLinkFile = "%linkPath%\%linkName%.LNK" >> temp.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> temp.vbs
echo oLink.TargetPath = "%program%" >> temp.vbs
echo oLink.IconLocation = "%iconFile%, %icon%" >> temp.vbs
echo oLink.WindowStyle = "%windowStyle%" >> temp.vbs
echo oLink.WorkingDirectory = "%workdir%" >> temp.vbs
echo oLink.Save >> temp.vbs

WScript.exe temp.vbs
del temp.vbs

rem #
rem ### Show Popup Message box after everything completed /zaib
rem #

mshta javascript:alert("Dialer Installation Completed!!!\n\Please Restart you computern ,Thank You\n\Syed.Jahanzaib! aacable@hotmail.com");close();

rem # THE END #

Now execute it from c:\dialer.bat & then restart your computer. If you dont want to restart the newly created connection will not show in network connections, You have to press F5 in the network connections to display the newly created profile. After restart it will appear auto in network and sharing center.

After successful lab testing, its time to make it a distributable package. To convert it in executable package, you download BATCH to EXE converter.


http://www.f2ko.de/downloads/Bat_To_Exe_Converter.zip

extract and run Bat_To_Exe_Converter.exe

Fill up the required info as shown in teh images below and click on compile.

1- compile

and click on COMPILE , it will create .exe Package. You can also add additional info like ICON file , or product version or info

As showed in the image below . .

2- compile

.

.

End results 🙂

3- info

Regard’s
Syed Jahanzaib

April 3, 2013

Windows Server 2008 R2 Active Directory Reference Guide.


Howto enable RECYCLE BIN in Widnows 2008 Active Directory Server.

Pre requisite to enable Recycle Bin in Windows 2008 Active Directory.

1- Domain controller must be Windows 2008 R2 or later.
2- Forest and domain functional levels must be Windows Server 2008 R2, If not , then first raise functional level to windows 2008 R2 using ADUC
3- Enable Recycle Bin using Power Shell. Follow the below to do so
> Open powershell by using CMD and type powershell
> Load AD module by using following command.

Import-Module ActiveDirectory

Now activate Recycle BIN using following command

Enable-ADOptionalFeature -Identity ‘CN=Recycle Bin Feature,CN=Optional Features,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration,DC=zaib,DC=com’ -Scope ForestOrConfigurationSet -Target ‘zaib.com’

Note: Change the zaib , com and zaib.com to match your local domain name

Delete any single user from AD for test purpose

> Now delete any user for test purpose via AD or net command

> From Powershell , Search for deleted items using following commands (TIP: To execute commands related to AD, always load module ActiveDirectory after you launch PowerShell)

Get-ADObject -Filter {name -like “*test*” -and deleted -eq $true} -IncludeDeletedObjects

Note: Change the *test to match the name or portion of delete user name

Restore Deleted User

To restore the deleted account, use following command

Get-ADObject -Filter {name -like “*test*” -and deleted -eq $true} -IncludeDeletedObjects | Restore-ADObject

If you want to use GUI for easy access, then you can try ADRecycleBin.exe (Active Directory Recycle Bin) which allows administrators to quickly restore deleted Active Directory objects via an easy to use GUI (Graphical User Interface). This is a free Active Directory Recycle Bin tool. You can download it from

http://www.overall.ca/index.php?option=com_content&view=article&id=40:adrecyclebin&catid=15:adrecyclebinexe&Itemid=66

 

Backup and restore system state in windows 2008

Following is an small howto of ‘Backup and restore system state in windows 2008

BACKUP

1- First install the backup features from the Server Manager.
2- Open command prompt and type

wbadmin start systemstatebackup -backuptarget:d:

and press enter. It will ask for confirmation, Type Y to continue

Note: You can use a different backup target of your choosing, it must be a local drive of your server.

When the backup finishes running, you should get a message that the backup completed successfully. Goto your backup drive and you will find folder name WindowsImageBackup with backup data.

RESTORE (Authoritative)

– To restore backup, Boot Windows 2008 in Directory Services Restore Mode (DSRM)

– Open command prompt , First you need to get backup version number so that you may restore correct version of backup, use the followign command to get the version number

wbadmin get versions

– Write down the version you need to use.

– To restore AD in AUTHORITATIVE mode (Usually used for DC), use the following command

wbadmin start systemstaterecovery -version:04/04/2013-15:00 –authsysvol

Note: Change the -version: to match your backup number that noted from wbadmin get version command

– To restore AD in non-authoritative mode, remove the –authsysvol syntax at the end of the command (Usually used at ADC)

To get mroe info, please visit http://www.trainsignal.com/blog/backup-and-restore-active-directory-on-windows-server-2008 for more detailed step by step guide with snapshots

Regard’s
Syed Jahanzaib

March 26, 2013

Howto remove your mail server IP from HOTMAIL black list

Filed under: Microsoft Related — Tags: , — Syed Jahanzaib / Pinochio~:) @ 1:32 PM

Recently Hotmail started to reject emails coming from our domain , giving following error.

Error transferring to mx4.HOTMAIL.COM; SMTP Protocol Returned a Permanent Error 550 SC-001 (SNT0-MC2-F23) Unfortunately, messages from xxx.xxx.xxx.xxx weren't sent. 
Please contact your Internet service provider since part of their network is on our block

I checked at mxtoolbox.com website mail server blacklist checker and all over the internet in all possible dns black lists but my IP address was not listed and it was clean. I then signed in to Microsoft Smart Network Data Services at  https://postmaster.live.com/snds/ and found out that my IP address was in Hotmail black list.

ip-block-status

I found out that Microsoft has an Eform for De-Listing / removing spam blacklisted mail server IPs not able to deliver to Hotmail and live.com.

Fill out the below form (you must have registered id of outlook/hotmail)

https://support.microsoft.com/en-us/getsupport?oaspworkflow=start_1.0.0.0&wfname=capsub&productkey=edfsmsbl3&locale=en-us&ccsid=636201367492016455

It will ask you Contact name, Contact e-mail address, Enter your Email Server Public IP in  Outbound IP(s) or range(s) and other details it asks, and submit, You will receive a ticket number and it may take upto 2-4 days for your request to be entertained. Hopefully they will remove it from there black list. It also happens if you sent email to any user and he mark it as junk/unwanted then it auto adds in Hotmail monitoring system.


TIP- 1:

Using Internet Explorer I received an ‘error occurred’ while submitting the above form, After using Google Chrome (or firefox) latest version I was able to successfully submit the form.

More info can be found here.

http://pc-freak.net/blog/howto-remove-delist-your-mail-server-ip-from-hotmail-live-com-and-msn-mail-server-blacklist/

TIP- 2:

In such situation when your public ip added to blacklist, you can use your ISP smtp/smarthost to relay mail. This way your ip will hide under the ISP smtp relay IP which usually works fine as ISP’s maintain their mail relay system up to date very efficiently


Regard’s
Syed Jahanzaib

March 25, 2013

NTBACKUP commmon issue and there fixes


In our company, we are using TAPE drives to backup our data on various servers. It was running successfully since many years, but from past few weeks, it started to create strange issues and backup were failing with multiple errors in logs , for example

Logs Error # 1

Volume shadow copy creation: Attempt 1.
Timeout before function completed
Error returned while creating the volume shadow copy:0x80042319.
Error returned while creating the volume shadow copy:80042319
Aborting Backup.
----------------------
The operation did not successfully complete.
----------------------

Logs Error # 2

Volume shadow copy creation: Attempt 1.
Timeout before function completed
Error returned while creating the volume shadow copy:0xffffffff.
Error returned while creating the volume shadow copy:ffffffff
Aborting Backup.
----------------------
The operation did not successfully complete.
----------------------

This error occurs when the creation of the Volume Shadow Copy times out.
This is more common during periods of high disk activity, or on disks that are heavily fragmented.
To solve it, Try following solutions

1- Make sure you have Latest Service pack for windows 2003 Server, If don’t Update it first,
Now Download HOTFIX from
http://support.microsoft.com/kb/833167/en-us
OR http://hotfixv4.microsoft.com/Windows%20Server%202003/sp1/Fix67560/3790/free/158865_ENU_i386_zip.exe

After applying, restart your server and try NTBACKUP again. If the problem persists, then continue below

2- Set following services startup type to AUTOMATIC , and start them

– Microsoft Software Shadow Copy Provider
– Virtual Shadow Copy
– Volume Shadow Copy (VSS)
– Remote Procedure Call (RPCSS) – should be enabled as “Automatic”
– COM+ Event System (eventsystem)
– System Event Notification Service (sens) – should be enabled as “Automatic”

Adjust above services accordingly and now try NTBACKUP again.

3- Re-Register few dll’s ,Open command prompt and copy paste following lines.

Net stop vss
Net stop swprv
regsvr32 ole32.dll  
regsvr32 oleaut32.dll
regsvr32 vss_ps.dll  
vssvc /Register
regsvr32 /i swprv.dll
regsvr32 /i eventcls.dll
regsvr32 stdprov.dll
regsvr32 es.dll
regsvr32 vssui.dll
regsvr32 msxml.dll
regsvr32 msxml2.dll
regsvr32 msxml3.dll
regsvr32 msxml4.dll

Now Restart your server and try NT.Backup again. Hopefully it will work fine :), at least in my case, it DID 🙂

Mounting the media . . .

If you run NTBackup from Windows, and it says “Waiting for a previous media operation to finish” but actually there is none. OR if you see MOUNTING THE MEDIA  and it keep stucked on this message. Then Try following . . .

Go to Computer Management -> Removable Storage and check under the Work Queue for any errors. Deleting any jobs that are failing should resolve your problem. However, you may be experiencing hardware issues with the drive or the media, which would be worth checking out.

In some cases restarting the Removable Storage service has worked OR
In some cases, rebuilding the Removable Storage Database has worked for me.

To rebuild RSM Database, Follow below steps

1) Go to Start > Control Panel > Administrative Tools > Services and find the Removable Storage service.
2) Right click on the Removable Storage service, select Properties, change the ‘Startup type:’ to Disabled and click ok.
3) Restart the machine
4) When the machine is running again open Windows Explorer and navigate to the C:\Windows\system32\ntmsdata\ directory  (or some other variation depending on the operating system, just pick the directory where Windows is installed and go from there)
5) In that directory rename all the files to *.OLD or move them to another temp folder.
6) Go back to the Removable Storage service (see step 1) go to properties and change the ‘Startup type:’ back to Automatic.
7) Restart the machine again

The device reported an error on a request to write data to media.

IF you receive the following error in NTBACKUP logs

Error: The device reported an error on a request to write data to media.
Error reported: Bad data.
There may be a hardware or media problem.

# Clean your tape drive either by using Cleaning Tape or other means (by service technician)

 

Regard’s
Syed Jahanzaib

March 5, 2013

Windows 2008 Group Policy ! Fun Things to DO


Howto disable Windows Firewall using Group Policy in Windows 2008

I personally don’t think it’s the best way to disable windows firewall specially in a large network environment, but recently I was in a situation where I needed it to avoice some arguments with few co workers. Here is how you can do it on a Windows 2008 server.

Open Group Policy Management,
Select the policy to edit (Usually: the default policy), right-click and choose Edit.
Go to Administrative Templates > Network > Network connections > Windows Firewall > Domain Profile.
Disable the “Protect All Network connections” rule.  Do the same for the “Standard Profile”, as well.

Now, all that’s left to do is update the clients.  Default Update time for group policy is 6 hours, but you can push it forcefully by using following command:

gpupdate / force

then simply log off and log on the client again.

Disabling Action Center’s Firewall Notification through GPO

As far as I know, there is not a policy that will disable only the Firewall Notification. The closest options we could configure are two policies that are related but neither is really a complete solution and will block other types of notifications as well:

1) Disable all balloon notifications:

User Configuration \ Administrative Templates \ Start Menu and Taskbar \ Turn off all balloon notifications

2) Disable Action Center itself:

User Configuration\Administrative Templates\Start Menu and Taskbar \ Remove the Action Center icon
(Thanks for the TIP from http://social.technet.microsoft.com/Forums/en-US/winserverGP/thread/e78a30cb-6cf2-4de6-afda-e0c90a3d2e34/ )

Disabling Your Security setting level puts your computer at risk notification

If your users are complaining of the appearance of the message box in Internet Explorer 7/8 telling that
Your Security setting level puts your computer at risk.”

To fix it, There are two ways to resolve this:

1. Set “Initialize and script ActiveX controls not marked as safe for scripting” to Disable (recommended) under Security SettingsInternet Zone or Restricted Sites Zone

2. Enable the following GPO via Domain Group Policy at your Domain controller.

Goto Local Computer Policy
User Configuration
Administrative Templates
Windows Components
Internet Explorer
ENABLE this setting >  Turn off the Security Settings
Regard’s
Syed Jahanzaib

February 22, 2013

Start windows service under different user credentials

Filed under: Microsoft Related — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 3:02 PM

To start windows service under another user credentials , Use following

In Windows 2003:

IF the user belongs to local system

sc.exe config SERVICENAME obj= .\USERNAME password= 123456
net start “SERVICENAME”

OR

IF the user belongs to Domain

sc.exe config SERVICENAME obj= DOMAIN_NAME\syed.jahanzaib password= 123456
net start “SERVICENAME”

TIP: Make sure you add SPACE after each equal sign in command .

For example: obj= SERVICENAME

It was required for me to start SAP services, after configuring user account with password in services console, they remove password after every restart of system, therefore I made this batch file to execute on startup so they start automatically upon reboot.

Regard’s
Syed Jahanzaib

January 16, 2013

Active Directory DSQUERY & Miscellenous Commands with Syntax


Recently We were asked by the Auditors to provide some data of Active Directory for yearly Audit purpose. I already have few scripts that saved a lot of time. I also linked these scripts with the Linux base WEBMIN, so they can be called by nice GUI as showed in the example below.

Image

.

<How to link Linux base scritps with the webmin>

Following are scripts

Show All users in your domain

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User))” -limit 0

Show All Users Created Since 1st January, 2012 till date

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User)(whenCreated>=20120101000000.0Z))”

Show Users For Specific Period (Jan-2012 till Dec-2012)
e.g: Display Users Created from 1st January 2012 till 31st December 2012 (1 Year) Only.

dsquery * dc=yourdomainname -filter “(&(objectCategory=Person)(objectClass=User)(whenCreated>=20120101000000.0Z-)(whenCreated<=20121231000000.0Z-))”

> = greater then
< = less then
~ = approx
= equals

Miscellaneous commands . . .

Show All Users Info (Active/Non Active)
dsquery user -limit 0 | dsget user -dn -disabled

Show Inactive Users Only (Users that haven’t logged on since last 2 weeks)
dsquery user “dc=Your_Domain_Name” -inactive 2

Show DISABLED Users Only
dsquery user -disabled | dsget user -display -email -dept -title

Show ACTIVE Users Only
dsquery * -filter “(&(sAMAccountType=805306368)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))” -limit 0 | dsget user -display -email -dept -title

Show Users from Specific Group Only
dsquery group DC=yourdomainname -name “Type Group Name” | dsget group -members |sort |dsget user -display -email -dept -title

Show Only Specific User Details
Net user USERID /domain

Delete Only Computer Name from AD Computers
dsquery computer -name PCNAME  |dsrm  -subtree -c -noprompt

 

Regard’s
Syed Jahanzaib

Backup Files via CMD/Batch/ntbackup Scripts [Personnel Notes]


Salam to All,

Following are few backup batch files that I have used at my office to perform backup operation using scheduled backup tasks. I am posting them just for reference so they can be used as archiving or possibly useful for others too having same task.

DELETE FOLDERS OLDER THEN XX DAYS USING POWESHELL
[Added 16th October, 2015]

To delete FOLDERS (including files or sub folders) older then X days, you can use following powershell command, fully tested with windows 2008


PowerShell -Command "& Get-ChildItem "D:\Data" | Where-Object {$_.PSIsContainer -and $_.LastWriteTime -le [System.DateTime]::Now.AddDays(-3)} | Remove-Item -Recurse -Force"


Move Files to another folder/drive using ROBOCOPY – Older then 365 Days


robocopy D:\Users\Syed_Jahanzaib  X:\Users\Syed_Jahanzaib_Archive /MOVE /MINAGE:365 /E

There is confusion here and elsewhere, I believe the following is correct:

  1. minage and maxage actually refer to the last modified date of the file (not creation date)
  2. minlad and maxlad actually refer to the last access date of the file.

 


 

Few days back, a new oracle server was added in our IT dept. It is an oracle database server which serves many users request in our company. There was an annoying manual backup task that we have to perform on it on daily basis , the :@ task was to run 2 shortcut which creates backup dump files in E: drive, and then we have to manually rename the 2 dump files according to current date and then move them in other date-wise folder.

Quite annoying , isn’t it ? I mean still do we have to perform simple tasks like taking backup manually where every task is being done Automatically ?
Stupid enough ! 😛

It was quite easy to do this task automatically in LINUX environment, but as currently i am working in MS (Microshit or Microsoft environment) I manage to done it with built-in DOS commands. Following is the complete dos batch file or call it the Backup script 😉 , I just added in Schedule task, Now it runs daily and saves my time.

@echo off
Echo Oracle Backup Organizer Script.
Echo Developed by Syed Jahanzaib / aacable@hotmail.com
Echo Make sure you have the backkup folder where backup is copied on daily basis by other script.
Echo Setting current date
set dt=%date:~-4,4%%date:~-10,2%%date:~-7,2%

Echo Map File Server backup folder in local computer using admin account.
net use B: \\FILES_SERVER\D$\home\cic /USER:zaib-admin@localdomain admin-passwd

Echo Copying already created oracle Dump files (which you can create by using backup file scheduled to run daily)
Echo into remote file server with current date for backup - FILES_SERVER

copy e:\backup\Cic_final.Dmp B:\cic-backup.%dt%.dmp
copy e:\backup\nae_final.dmp B:\nae-backup.%dt%.dmp

Echo Renaming dump files to current date for the date wise backup
ren e:\backup\Cic_final.Dmp cic-backup.%dt%.dmp
ren e:\backup\nae_final.dmp nae-backup.%dt%.dmp

echo.
echo All Backup done. Allah Hafiz


NTBACKUP with EMAIL the LOGS and START/END Time Report

This Script will first backup the data defined in “backup-data” to Tape Drive (In my case it was IBM LTO-3) and then email the LOG to your defined email addresses (in “mail-to” section) It will also record the total time of the backup and will attache it to the email.

@echo off
rem # Syed Jahanzaib #
rem #######################################################
rem Setting various Descriptions via environment variables
rem #######################################################

setlocal enableextensions enabledelayedexpansion
set starttime=%time%
set dt=%date:~-4,4%%date:~-10,2%%date:~-7,2%
set logpath="C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows NT\NTBackup\data"
set srvname=SERVER_X
set backup-data=C:\backup\Tape Backup of Different Data.bks
set description=SERVER_X - Autobackup Different Data
set jobname=SERVER_X - Tape Backup of Different Data
set attachment=C:\backup\SERVER_X-ntbackup-%dt%.txt
set mail-subject=SERVER_X-NTBACKUP LOG for Different Data
set mail-body=SERVER_X-NTBACKUP LOG for Different Data
set mail-to="aacable@hotmail.com","aacable@hotmail.com"
set footer=Automated Backup and Email Logs Script Created by Syed_Jahanzaib

rem ######################################
rem Starting Backup in IBM LTO3 Tape Drive
rem ######################################

c:\windows\system32\rsm.exe refresh /lf"IBM ULT3580-TD3 SCSI Sequential Device"
ping -r 9 127.0.0.1 >null
start /wait C:\WINDOWS\system32\ntbackup.exe backup "@%backup-data%" /n "%jobname%" /d "%description%" /j "%jobname%" /l:s /p "LTO Ultrium" /UM /v:no /r:yes /rs:no /hc:on /m normal

rem ############
rem NTBackup END
rem ############

rem ### Copy current date LOG to C:\backup
forfiles -p %logpath% -s -m *.log -d 0 -c "cmd /c copy @file %attachment%"

rem #########################
rem STart END Time Algorithm
rem #########################

ping -n 2 127.0.0.1 >nul: 2>nul:
set endtime=%time%
set total="echo Total   = %tot%"

set /a hrs=%endtime:~0,2%
set /a hrs=%hrs%-%starttime:~0,2%

set /a mins=%endtime:~3,2%
set /a mins=%mins%-%starttime:~3,2%

set /a secs=%endtime:~6,2%
set /a secs=%secs%-%starttime:~6,2%

if %secs% lss 0 (
    set /a secs=!secs!+60
    set /a mins=!mins!-1
)
if %mins% lss 0 (
    set /a mins=!mins!+60
    set /a hrs=!hrs!-1
)
if %hrs% lss 0 (
    set /a hrs=!hrs!+24
)
set /a tot=%secs%+%mins%*60+%hrs%*3600

echo End     = %endtime%
echo Start   = %starttime%
echo Hours   = %hrs%
echo Minutes = %mins%
echo Seconds = %secs%
echo Total   = %tot%

rem ##########
rem Email LOGS
rem ##########

c:\blat\blat.exe -to %mail-to% -i %srvname% -s "%mail-subject%" -body "%mail-body%|Backup Report:|Start   = %starttime%|End     = %endtime%|Hours   = %hrs%|Minutes = %mins%||%footer%" -attach %attachment%

endlocal

rem ## THE END
rem ## Syed Jahanzaib / aacable@hotmail.com

 

To delete files olde then X days using FORFILES

forfiles /p “C:\test” /s /m *.* /c “cmd /c del @path” /d -15

Change /d -15 to match your requirements. you can change the del command to any other like to show the files, use echo. FORFILES is builtin command with Windwos 2003 /7. You can download it from
http://www.ipass.net/davesisk/forfiles.zip


Delete Files Over 15 Days Old using ROBOCOPY

set _robodel=%TEMP%\~robodel
MD %_robodel%
ROBOCOPY “C:\source_folder” %_robodel% /move /minage:15
del %_robodel% /q


 

Batch File to create Windows MS SQL Backup

First create .sql file that can be called from batch file to create any specific DB backup.

for example c:\zaibdb.sql

BACKUP DATABASE [Promo] TO  DISK = N'D:\DataBaseBackup\zaibdb.Bak' WITH NOFORMAT, INIT,  NAME = N'Promo-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

now create a batch file which will call the above .sql file to start backup.

for example c:\start_backup.bat

@echo off
echo Creating FULL backup in D:\zaibdb.back
echo %Date% >> D:\DataBaseBackup\zaibdb.txt
sqlcmd -S .\SQLEXPRESS -i c:\zaibdb.sql > D:\DataBaseBackup\zaibdb.txt
echo.
echo Done
rem ping 127.0.0.1 -n 10 > null
echo . >> D:\DataBaseBackup\zaibdb.txt
echo This backup set was last created at %Date%  >> D:\DataBaseBackup\zaibdb.txt
echo.


Another Backup script that map remote  server folder locally
and then copy the required files and then delete the files older then 20 days

@echo off
rem Syed Jahanzaib / ??? (Pvt) Ltd. IS Dept.
rem This file will copy the today's SAP exports and cofiles only to files_server\export folder,
rem which is actually mapped locally as B: drive.
rem #
rem #
rem #
rem # Mapping files_server Folder via agpis Credentials
net use B: \\files_server\

rem # Copying Last Date Export files to \\file-server\B:\export folder
forfiles -p "J:\required_folder" -s -m *.* -d 0 -c "cmd /c copy @path B:\"

rem # Copying Last Date cofiles data to \\file-server\B:\cofiles folder
forfiles -p "J:\required_folder" -s -m *.* -d 0 -c "cmd /c copy @path B:\"

rem # Deleting export older then 20 Days . . .
forfiles -p "J:\required_folder" -s -m *.* -d -20 -c "cmd /c del @path"

rem # Deleting cofiles Logs older then 20 Days . . .
forfiles -p "J:\required_folder" -s -m *.* -d -20 -c "cmd /c del @path"

.


 

Daily Backup of Required Folder using ROBOCOPY

Robocopy method which will copy only new file by matching source and destination folder/file timstamps. Its much better as it displays results in command prompt with percentage and all the necessary info any admin want. 🙂 its my favorite. You can downlod Robocopy by downloading Microsoft Resource Kit from following link.
http://www.microsoft.com/en-us/download/details.aspx?id=17657

@echo off
Robocopy /E /LOG:h:\Softwares\Servers_Related\mail-backup-log.txt B:\archive\.  T:\backup\archive
Robocopy /E /LOG+:h:\Softwares\Servers_Related\mail-backup-log.txt T:\mailserver\c$\mt\.  T:\backup\mt
Robocopy /E /LOG+:h:\Softwares\Servers_Related\mail-backup-log.txt T:\mailserver\mail\.  T:\backup\mail

Second Version of robocopy which add logs, and emails too


@echo off
rem # Syed Jahanzaib #
rem #######################################################
rem Setting various Descriptions via environment variables
rem #######################################################

setlocal enableextensions enabledelayedexpansion
set starttime=%time%
set srvname=FILE_SERVER
set description=Target_Server - Daily Status of MAIL Server Data Copied in FILE_SERVER
set jobname=Target_Server - Daily Status of MAIL Server Data Copied in FILE_SERVER
set attachment=c:\backup\mail_backup_log.txt
set mail-subject=Target_Server - Daily Status of MAIL Server Data Copied in FILE_SERVER
set mail-body=Target_Server - Daily Status of MAIL Server Data Copied in FILE_SERVER
set mail-to=aacable@hotmail.com
set footer=Automated Backup and Email Logs Script Created by  / Syed Jahanzaib

rem Delete old mail backup log file
del c:\backup\mail_backup_log.txt
rem oNLY Mail NSF files Backup
Robocopy.exe *.nsf /w:0 /r:0 /LOG:c:\backup\mail_backup_log.txt /NP /FP /TEE /ts  \\Target_Server\d$\lotus\domino\data\mail H:\Target_Server\Target_Server_LIVE_DATA\MAIL

rem Mail Tracking Backup
Robocopy.exe *.nsf  /w:0 /r:0 /LOG+:c:\backup\mail_backup_log.txt /NP /FP /ts /TEE \\Target_Server\c$\mt\ H:\Target_Server\Target_Server_LIVE_DATA\Target_Server-MT

rem Transaction Logs for mail server
Robocopy.exe *.txn /w:0 /r:0 /LOG+:c:\backup\mail_backup_log.txt /NP /FP /TEE /ts \\Target_Server\c$\logdir\. H:\Target_Server\Target_Server_LIVE_DATA\LOGDIR

set endtime=%time%
set total="echo Total   = %tot%"

set /a hrs=%endtime:~0,2%
set /a hrs=%hrs%-%starttime:~0,2%

set /a mins=%endtime:~3,2%
set /a mins=%mins%-%starttime:~3,2%

set /a secs=%endtime:~6,2%
set /a secs=%secs%-%starttime:~6,2%

if %secs% lss 0 (
set /a secs=!secs!+60
set /a mins=!mins!-1
)
if %mins% lss 0 (
set /a mins=!mins!+60
set /a hrs=!hrs!-1
)
if %hrs% lss 0 (
set /a hrs=!hrs!+24
)
set /a tot=%secs%+%mins%*60+%hrs%*3600

echo End     = %endtime%
echo Start   = %starttime%
echo Hours   = %hrs%
echo Minutes = %mins%
echo Seconds = %secs%
echo Total   = %tot%

rem ##########
rem Email LOGS
rem ##########

c:\backup\blat\blat.exe -to %mail-to%  -attach %attachment% -i %srvname% -s "%mail-subject%" -body "%mail-body%|Backup Report:|Start   = %starttime%|End     = %endtime%|Hours   = %hrs%|Minutes = %mins%||%footer%"

endlocal

rem ## THE END
rem ## Syed Jahanzaib / aacable@hotmail.com

The above commands description is as follows.
/E  = Copy sub-directories, including Empty ones
/LOG+ = Output status to LOG file (append to existing log, so previous entries along with new one should be saved together, if you don’t use + , it will overwrite existing log-file, means delete old entries and overwrite new one)).


 

XCOPY Method

Following file will copy all the data from the source folder to target folder using windows builtin copy tool XCOPY.

@echo off

echo * * *  >> C:\backup-log.txt
echo Mail Backup Starts at %date% - %time%  >> C:\backup-log.txt

C:\windows\system32\xcopy.exe B:\source-folder\*.*  T:\targetfolder /S /D /C /Y

echo Mail Backup Ends at %date% - %time%  >> C:\backup-log.txt
echo * * * >> C:\backup-log.txt 

The above commands description is as follows.

/S = Copies directories and sub-directories except empty ones.
/D =  If no date is given, copies only those files whose  source time is newer than the destination time.
/C = Continues copying even if errors occur.
/Y  = Overwrite existing files if any without prompting, its necessary when you are running xcopy via batch / script file.


 

NET USE SHARING by COMMAND


net use B: \\server\datafolder /USER:administrator@mydomain password

net use B: \\server\datafolder /USER:pc-name\administrator password

 


Set Windows 7/x IP address via COMMAND / CLI

@echo off
echo.
echo Setting IP Address to AUTO DHCP [Office DHCP Server]...
echo.
netsh interface ip set address name="Local Area Connection" source=dhcp
netsh interface ip set address name="Wireless Network Connection" source=dhcp
echo.
echo.
echo Done....
echo.
pause

 

Regard’s
Syed Jahanzaib

« Newer PostsOlder Posts »

Blog at WordPress.com.