Tuesday, May 28, 2013

CentOS - Check for large files & directories


FILES

Check for large files over 9 MB in the file system,  in this example /home :
find /home -type f -xdev -size +9000000c -exec ls -ldh {} \;|sort -k 5n

- The xdev option tells it not to cross mount points.
- The exec option instructs the find command to issue an ls -ldh against any file that meets our criteria.
- The resulting matches are substituted inside the {}, and then executed.
- Then the results of the ls -ldh output is sent to the sort and sorted based on the 5th column which is the size column.


DIRECTORIES

du -H --max-depth=1 /home/ | sort -n -r

Friday, May 24, 2013

Powershell script to Delete/Remove AD user account & Exchange mailbox

1. Create the file ADUserDel.ps1 .  Will dump the mailbox to the location, \\SERVERNAME\SHARENAME\mailbox.pst

$Name = Read-Host "Please enter a mailbox to archive"
New-MailboxExportRequest -Mailbox $Name -FilePath \\SERVERNAME\SHARENAME\$Name.pst
while ((Get-MailboxExportRequest -Mailbox $Name | Where {$_.Status -eq "Queued" -or $_.Status -eq "InProgress"}))
{
sleep 60
}
Get-MailboxExportRequest -Mailbox $Name | Remove-MailboxExportRequest -Confirm:$false
Remove-Mailbox -Identity $Name -Confirm:$false

2. Execute the file from within the Exchange Shell

Network Policy Server (NPS) Backup

1. Create a batch file.  Will keep 7 days of backup files.

cd c:\
cd \Backup\nps
netsh nps export filename="c:\backup\nps\%Date:~0,3%.xml" exportPSK=YES
netsh nps show config > "c:\backup\nps\%Date:~0,3%Readable.txt

2. Schedule the batch file to run once a day.

3. First netsh nps line exports the config into an xml file.  The xml file can be imported using
netsh nps import  , command.  Second netsh nps line will dump the config into a readable text file for information.



DHCP Scheduled Backup

1. Create a batch file for DHCP backup.  This file will keep the last 7 days of dhcp backups.

cd c:\
cd \Backup\dhcp
rmdir %Date:~0,3%
md %Date:~0,3%
cd %Date:~0,3%
netsh dhcp server export dhcpdb all

2. Create a scheduled job to run the batch file every day

Thursday, May 23, 2013

MDT 2012 - custom files

Not necessary to do this, but helps.  Files go in the D:\DeploymentShare\Control  folder.  Be sure to change all values between *CHANGE*

BOOTSTRAP.INI

[Settings]
Priority=Default

[Default]
DeployRoot=\\*SERVERNAME*\DeploymentShare$
SkipBDDWelcome=YES
UserID=*USERNAME*
UserDomain=*DOMAINNAME*
UserPassword=*PASSWORD*

________________________________________
DOMAINOULIST.XML

<?xml version="1.0" encoding="utf-8"?>
<DomainOUs>
<DomainOU>OU=Desktops,OU=Computers,OU=SCC,DC=domain,DC=local</DomainOU>
<DomainOU>OU=Laptops,OU=Computers,OU=SCC,DC=domain,DC=local</DomainOU>
<DomainOU>OU=Others,OU=Computers,OU=SCC,DC=domain,DC=local</DomainOU>
</DomainOUs>

________________________________________
CUSTOMSETTINGS.INI

[Settings]
Priority=Default
Properties=MyCustomProperty
Properties=DriversApplied

[Default]
OSInstall=Y
SkipCapture=YES
SkipAdminPassword=YES
AdminPassword=*PASSWORD*
SkipProductKey=YES
SkipComputerBackup=YES
SkipBitLocker=YES
SkipApplications=NO
SkipUserData=YES
KeyboardLocale=en-US
UserLocale=en-CA
UILanguage=en-US
SkipDomainMembership=NO
JoinDomain=*domain.local*
DomainAdmin=*USERNAME*
DomainAdminDomain=*DOMAIN*
DomainAdminPassword=*PASSWORD*
SkipTimeZone=YES
TimeZone=035
TimeZoneName=Eastern Standard Time
WSUSServer=http://*SERVERNAME*:8530
DriversApplied=NO

MDT 2012 - Drivers using selection profiles


MDT 2012 – Drivers

Using selection profiles for hardware drivers.  Works well when most systems are standard models from vendors (HP, Dell, …).

STEP 1

Need a custom property called DriversApplied and set it to NO in the CustomSettings.ini

[Settings]

Priority=Default

Properties=DriversApplied

[Default]

DriversApplied=NO

 

STEP 2

Organize your drivers in the Deployment Workbench under the Out-of-Box Drivers.  Import the drivers into the appropriate folder.



STEP 3

Create a selection profile for each model/OS/architecture you have.  Created under Advanced Configuration.



Also, you will need a “catch all” selection profile to catch all others that do not match an exact profile.  Simply create another profile, but select every single folder under x86 to “catch” all 32 bit drivers.

 

STEP 4

After creating all your driver selection profiles (both machine specific and a “catch all) , you have to modify the task sequence.  In the Preinstall phase, REMOVE the Inject Drivers step and create a group called Inject Drivers.  Then create a subgroup inside for each model you have created a selection profile for.



 

On each subgroup, select it, on the right select the Options Tab, Add a Query WMI .  Query is,

Select * from Win32_ComputerSystem where Model like 'HP EliteBook 2540p%'



Use PDQ Inventory, Computer selected to find the exact text for the Model to match the query.

In each subgroup for each model, you have to create 2 steps, one to inject the drivers from the selection profile



 and another to change the value of DriversApplied to YES.



 

Final step in this group is to create a the “catch all” inject drivers step,



Set it to only run when DriversApplied equals NO.



 

Thursday, May 16, 2013

Backup local files to home share

For Windows 7, batch file to copy contents of users' Desktop and Documents to a home share.

robocopy "%USERPROFILE%\Desktop" "%HOMESHARE%\Desktop" /MIR /R:2 /W:3
robocopy "%USERPROFILE%\Documents" "%HOMESHARE%\Documents" /MIR /R:2 /W:3


For XP or where robocopy does not work.

rd /S /Q "%HOMESHARE%\Desktop"
rd /S /Q "%HOMESHARE%\Documents"
mkdir "%HOMESHARE%\Desktop"
mkdir "%HOMESHARE%\Documents"
xcopy "%USERPROFILE%\Desktop" "%HOMESHARE%\Desktop" /S /E /Y /C
xcopy "%USERPROFILE%\Documents" "%HOMESHARE%\Documents" /S /E /Y /C

Windows Variables

Variable Type Description
%ALLUSERSPROFILE% Local Returns the location of the All Users Profile.
%APPDATA% Local Returns the location where applications store data by default.
%CD% Local Returns the current directory string.
%CMDCMDLINE% Local Returns the exact command line used to start the current Cmd.exe.
%CMDEXTVERSION% System Returns the version number of the current Command Processor Extensions.
%COMPUTERNAME%  System Returns the name of the computer.
%COMSPEC%  System Returns the exact path to the command shell executable.
%DATE%  System Returns the current date. Uses the same format as the date /t command. Generated by Cmd.exe.
%HOMEDRIVE%  System Returns which local workstation drive letter is connected to the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%HOMEPATH%  System Returns the full path of the user's home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%HOMESHARE%  System Returns the network path to the user's shared home directory. Set based on the value of the home directory. The user's home directory is specified in Local Users and Groups.
%LOGONSEVER%  Local Returns the name of the domain controller that validated the current logon session.
%NUMBER_OF_PROCESSORS%  System Specifies the number of processors installed on the computer.
%OS%  System Returns the operating system name. Windows 2000 displays the operating system as Windows_NT.
%PATH% System Specifies the search path for executable files.
%PATHEXT% System Returns a list of the file extensions that the operating system considers to be executable.
%PROCESSOR_ARCHITECTURE%  System Returns the chip architecture of the processor. Values: x86 , IA64.
%PROCESSOR_IDENTFIER% System Returns a description of the processor.
%PROCESSOR_LEVEL%  System Returns the model number of the processor installed on the computer.
%PROCESSOR_REVISION% System Returns the revision number of the processor. 
%PROMPT% Local Returns the command prompt settings for the current interpreter. Generated by Cmd.exe.
%RANDOM% System Returns a random decimal number between 0 and 32767. Generated by Cmd.exe.
%SYSTEMDRIVE% System Returns the drive containing the Windows XP root directory (that is, the system root).
%SYSTEMROOT%  System Returns the location of the Windows XP root directory.
%TEMP% and %TMP% System and User Returns the default temporary directories that are used by applications available to users who are currently logged on. Some applications require TEMP and others require TMP.
%TIME% System Returns the current time. Uses the same format as the time /t command. Generated by Cmd.exe. For more information about the time command, see Time
%USERDOMAIN% Local Returns the name of the domain that contains the user's account.
%USERNAME% Local Returns the name of the user who is currently logged on.
%USERPROFILE% Local Returns the location of the profile for the current user.
%WINDIR% System Returns the location of the operating system directory.

Wednesday, May 15, 2013

Extract Images from Word, Excel Office 2007/2010 documents

Open the document with 7-Zip (or equivalent).  Images are stored inside the file in the folder,
word/media or xl/media.

CentOS - Install VMWare Tools after kernel update

create file vmware-checktools , touch vmware-checktools , contents of file below,

#! /bin/bash
# Following lines auto-recompile VM Tools when kernel updated
 VMToolsCheckFile="/lib/modules/`uname -r`/misc/.vmware_installed"
 VMToolsVersion=`vmware-config-tools.pl --help 2>&1 | awk '$0 ~ /^VMware Tools [0-9]/ { print $3,$4 }'`
 printf "\nCurrent VM Tools version: $VMToolsVersion\n\n"
 if [[ ! -e $VMToolsCheckFile || `grep -c "$VMToolsVersion" $VMToolsCheckFile` -eq 0 ]]; then
 [ -x /usr/bin/vmware-config-tools.pl ] && \
 printf "Automatically compiling new build of VMware Tools\n\n" && \
 /usr/bin/vmware-config-tools.pl --default && \
 printf "$VMToolsVersion" > $VMToolsCheckFile && \
 rmmod pcnet32
 rmmod vmxnet
 depmod -a
 modprobe vmxnet
 fi


copy the file vmware-checktools into the directory  /etc/init.d , cp vmware-checktools /etc/init.d

change permissions on the file,  chmod 755 /etc/init.d/vmware-checktools

create symbolic link in startup directory to the script, ln -s /etc/init.d/vmware-checktools /etc/rc3.d/S09vmware-checktools

CentOS - Setup Automatic / Scheduled Reboot


in /etc/cron.d create a file called reboot , touch reboot
inside the reboot file, vi reboot , enter the following

# Reboot system once a week on Sunday at 8AM
0 8 * * Sun root /sbin/reboot

CentOS - Setup Automatic Updates


CentOS 6.X

yum install yum-cron
chkconfig yum-cron on
service yum-cron start


CentOS 7.X

yum install yum-cron
systemctl enable yum-cron.service
systemctl start yum-cron.service
Edit the /etc/yum/yum-cron.conf  , change apply-updates=yes