Thursday, April 28, 2011

Search Active Directory for user properties

We are working on a project where we need to gather user telephone numbers from Active Directory in order to verify and normalize the telephone number filed.  This filed has to be formatted in a certain way and it also must be unique to a user, or the integration of Exchange and Cisco Unity Connection will not work.  My first thought was to use DSquery and DSget, but I decided to use the Get-ADuser Powershell cmdlet. 

In this case I just wanted First and Lastname and office telephone number.  So I used the following PS scripts 

From the Windows 2008 r2 AD Powershell Module:
Get-Aduser –Filter * -properties TelephoneNumber | FT Name,TelephoneNumber | Out-File C:\telnumberdump.txt

I like to dump results to TXT file, so I formatted the output  to deisplay Name and Telephone Number and then saved it to C: with Out-File. 


TechNet PS User Management

Backup and Restore NTFS and Share Permissions 2

NTFS permissions are stored as part of the file system itself, in an attribute in the Master File Table. So the backup and restore of NTFS permissions is somewhat different than Share Permissions.  Windows Server 2008 r2 is comes with a native utility to fulfill this purpose.

I used the following command to backup and restore the NTFS permissions: 
Backup and Restore NTFS:

icacls E:\Users\*   /save C:\NTFSPerm /T /C

The /T switch recourses through the directory to get sub folder and files, while the /C switch continues on error.

Restore:

icacls E:\ /restore C:\NTFSPerms.txt /C

When restoring the NTFS permissions only include the drive path and use the /C  switch to continue on error.

ICACLS Wiki

Friday, April 22, 2011

Backup and Restore NTFS and Share Permissions

We are in the process of migrating/upgrading our File and Application servers to Windows Server 2008r2.  Virtualization has really done away with hardware migration issues, but we still have to worry about OS and Application specific settings.

One task that is part of the server migration process is the backup and restore of the NTFS and Share permissions.  The Windows 2008 r2 server migration wizard facilitates the transfer of these settings, but I like to err on the side of caution and prefer to manually back them up. Share permissions are stored in the registry, so the backup of Share permissions is as easy as exporting a Registry Key.

Export the following reg key to a new file by right clicking on the Share reg Key and selecting Export.

HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares

CommandLine:
reg export HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Shares share.reg

To import by using the registry.exe, just double click on the reg key on the destination server.

CommandLin:
reg import share.reg

Windows Server 2008 VSS Space Usage

Quick note about Volume Shadow Copy (VSS).   VSS can be configured to use Space Limits or it can be configured to use all allocated space (No Limits).

When configured to use limits, VSS will purge old Snapshots when the limit is met.  No Limit configuration will start to purge the oldest Snapshots once physical allocated space has been used.  I chose to use the No limits option to maximize our Snapshot retention period.

Check Space used by VSS:
Vssadmin list ShadowCopyStorage

Thursday, April 14, 2011

PowerShell Script Get DirectorySize

This is more General Powershell script used to gather folder size infomration from our Home Directory server.

$startfolder = "E:\users\*"
$folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "True"}
"Directory Name`tDirectory Size (MB)"
foreach ($fol in $Folders){
$colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
$size = "{0:N2}" -f ($colItems.sum / 1MB)
"$($fol.name)`t$size"
}



Thanks to the "Hey Scripting Guy" team

Wednesday, April 13, 2011

Netbackup Commands

Useful Netbackup commands to help troubleshoot.

Verifies DNS resolution
C:\Program Files\veritas\netbackup\bin
bpclntcmd -hn ClientName

DNS Reverse Lookup
C:\Program Files\veritas\netbackup\bin 
bpclntcmd -ip ClientIP

Clear Resource Allocation
installpath\bin\admincmd
nbrbutil -resetall

Resource Allocation Log
nbrbutil -dump

Netbackup jjob cleanup fails with status code 83
Run the following command:
nbdelete -allvolumes -force

nbdelete can be found in the following locations:
Windows: <install_path>\VERITAS\NetBackup\bin\admincmd






Tuesday, April 12, 2011

Netbackup Display Tape Drive Status (vmoprcmd)

This command will display the status of all drives attached to a netbackup media server.   I usually run it from the master server.  This command can run with switches, but I get the results I need by executing it on its own.

1.    Command Prompt.
2.    Cd C:\Program files\VERITAS\volmgr\bin\vmoprcmd.

Monday, April 11, 2011

Netbackup Eject Tapes from library (VMchange)

One of the most time consuming and most disliked tasks of netbackup administration is the removal of Tape from the tape library for offsite storage. In the past we have used the Admin Console’s GUI to query the catalog for a specific time frame which would output job results for a specific date.  We then used the job results to eject associated Tapes from the library using the GUI. 

I’ve tried to automate this process by using vmchange.exe via a script but I have not been able to work it out.  The documentation says that a CSV can be generated to jnput the MediaIDs to the command, but this is where my trouble begins.  The command executes correctly, but the MediaIDs do not get fed into the command.  The CSV file has to be a Colon (: ) separated.  I’ve worked around this by typing in the MediaIDs in the command prompt in a colon separated list which is faster than looking for MediaID using the GUI. 

I will try PowerShell in an attempt to automate this process, but for moment this the command I use. 

1.    From a command prompt cd to the default install location
2.    C:\Program Files\Veritas\Volmgr\bin\vmchange.exe -res -multi_eject -sc -rn 0 -rt TLD -rh netbackup -vh netbackup -v scan -ml 000924:000925:000926 ext.



--rn=RobotNumber
--rt=RobotType
-rh=RobotHost
-vh=VolumeHost
-v=Volume (where mediaID resides)
-ml=MediaList (Colon separated TapeIDs)



...

Netbackup Generate list of TapeIDs to Eject (bpimagelist)

Netbackup Administration is fairly easy and a straightforward process, and in my opinion not as automated as I would like.  Unix based installation may be better at automation via scripts, but at least in my experience dealing with a Windows installation I’ve not seen to much automation. 

I’ve tried to automate the process of Tape removal from the library but I’ve not been able t make it work.  One of my challenges has been automatically generating the list of media to eject.  I’ve read in Forum posts on how to incorporate bpimagelist in a netbackup exit script , which would generate a file with associated TapeIDs of the completed job, but I ‘ve not seen one for a Windows install.  In the meantime this what I use to generate the media list. 

1.    Query the Catalog for a specific date in which a full job completed. 
2.    Use the result of the query to fill in the info needed by the bpimagelist command. 
3.    Info needed
-d Date of job
-Client ClientName
-l
-policy PolicyName
-backupid  BackupID
4. On a command Prompt CD to default install path
admincmd\bpimagelist -d 10/29/2010 -client megatron01 -l -policy megatronPol
 -backupid megatron-_1288325930 -media>C:\scripts\TapeID.txt

This produces a text file with the associated TapeIDs that can then be used with vmchange.exe to eject the tapes. 


Symantec TechNote



..........

Friday, April 8, 2011

PowerShell Script to move Directories

This powershell script will recursively search and move files if file name matches text patten.  I needed to find all Novell GroupWise Archives scattered about users home directories. 

get-childitem E:\users -recurse | ? {$_.PSIsContainer -eq $true} | ? {$_.Name -like 'of???arc'} | move-item -destination R:\users\Archives\

Exchange 2007 PS Script to purge W3SVC1 logs

We have had issues where the IIS logs have been filling up our C drive on both our Mailbox Servers . This is the result of IIS web and Active Sync activity. The following PowerShell Script will purge logs older than 5 days as scheduled Windows Task. 

get-childitem -Path C:\inetpub\logs\LogFiles\w3svc1 -recurse | where-object {$_.lastwritetime -lt (get-date).addDays(-5)} | Foreach-Object { del $_.FullName }

Thanks to the exchange 2007 Technet forums. 

Thursday, April 7, 2011

PowerShell Script to Calculate FolderSize

This script will recursively search through a directory looking for matching text patterns in the name and measure the size of the folder in MB.  This will also list the file path.  

...............................

Function FolderSize
{
$startFolder = "E:\users"

$colItems = (Get-ChildItem $startFolder |where {$_.Length}|Measure-Object -property length -sum)
"$startFolder -- " + "{0:N2}" -f ($colItems.sum / 1MB) + " MB"

$colItems = (Get-ChildItem $startFolder -Recurse -Include of???arc | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
foreach ($i in $colItems)
    {
        $subFolderItems = (Get-ChildItem $i.FullName |Measure-Object -property length -sum)
        $i.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB"
      
    }
    }
    FolderSize | Out-File C:\Temp\FolderSize.txt

................................................................................

Netbackup 7 Nbrbutil

Use the nbrbutil command to clear the allocation holds that the media server has placed.  The command can be run from the media server itself or the master server and is in the following path:

Windows: C:\Program Files\veritas\NetBackup\bin\admincmd\nbrbutil -resetall

nbrbutil -dump to dump log and diagnostic data. 

Windows: C:\Program Files\veritas\NetBackup\bin\admincmd\nbrbutil -resetall

Also available in the NBU command reference guide.  

Netbackup 7 Orphaned Jobs in Activity Monitor (Error Code 50)

Sometime in January I stopped a job from the activity monitor and it stopped with error code of 50.  I tried to lelete it from activity monitor but it did not delete..  After looking around Symantec Knolodge base I found a Technote that outlined the steps to delete the jobs database which removes orphaned jobs from the Activity Monitor.

1. stop NetBackup (bpdown) in the default folder: C:\Program Files\VERITAS\NetBackup\bin
2. bpps , kill the remaining processes
3. cd to install_path\veritas\netbackup\db\jobs
4. delete the bpjobd.act.db file  (Note: For Windows 2008, uncheck 'Hide extensions for known file types')
5. cd up to the restart folder
6. delete all files
7. cd..\trylogs
8. delete all files
9. cd..\ffilelogs
10. delete all files
11. restart NetBackup (bpup) in the default folder: C:\Program Files\VERITAS\NetBackup\bin

Technote

http://www.symantec.com/business/support/index?page=content&id=TECH43177

Wednesday, April 6, 2011

Exchange 2007 Clean-MailboxDatabase

When Active Directory accounts are disabled, associated mailboxes are disconnected, but do not show up under the Disconnected Mailxed under Exchange Management console.  Issue the following in the Exchange Management Shell. 

Clean-MailboxDatabase -identity db1


http://technet.microsoft.com/en-us/library/bb124076%28v=exchg.80%29.aspx

Exchange 2007 MailboxSize

From time to time we have to look report on the size of user Mailboxes, so this script will report the size of each mailbox. You can change the "TotalitemSize(MB) to GB if you want to report as Gigs.  The default is repoarted as kb.  This reports on a per mailbox server bases.

I like to write the results to a text file, that way I can then compare the text files using compare-object cmdlet to see how MailboxSize change. 

Get-MailboxStatistics | Sort-Object TotalItemSize -Descending | ft DisplayName,@{label="TotalItemSize(MB)";expression={$_.TotalItemSize.Value.ToMB()}},ItemCount | out-file C:\temp\mb1.txt

Netbackup 7.1 Unzip and Join split Files

I am getting ready to upgrade our Symantec Netbackup Enterprise Server from version 7.0 to 7.1.  I downloaded the Split file images and now have to join them.  On a windows system Command prompt cd to the location of the files and type in the following. Leave the original file names. 

copy /b "NetBackup_7.1_Win_zip.1of2"+"NetBackup_7.1_Win_zip.2of2" "NetBackup_7.1_Win.zip"


Exchange 2007 Database Size

This is a good way to report on Exchange 2007 database sizes.  ThisPowershell Script reports on the number of users per database.  I found the script in my notes and don't know who to give credit to.  

Get-MailboxDatabase | Select Server, StorageGroupName, Name, @{Name="Number Of Mailboxes";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}} | Format-Table -AutoSize

I like to write results to a text file, so I changed the Format-Table cmdlet to Out-File C:\temp\DbSize.txt