≡ Menu

Delete is not Delete…

When you delete a file from your system, it takes reasonably less time than the time it took for copying it. So what happens when you delete?  It won’t delete each bit/byte of information it copied to disk when file created; rather it just delete the link in File System Table so that it will be invisible for Operating System. Here you might get a doubt, “Why it is taking considerable amount time (though less than original creation time) for deletion if it has to delete just a link?”. In fact, it is my doubt and the I self-answered that, it might be because, there are many links in file system table that needs to be deleted. When you copy a file to your disk, there is no guarantee that all the file bites information will be stored at same location(sectors/cylinders) in hard disk. Operating system will spread the parts of file information to various locations of disk to utilize the free fragmented space. That is why we get more links in FAT and more time to delete links FAT. Fine, let’s come back to our original topic of file deletion and continue the rambling. So, for this reason, when you delete(Shift + Del) a file from system, it is NOT deleted from storage originally and there will be traces of your deleted files in disk. Your OS will not see them but by using third party utilities you can see these files. These third party utilities will directly talk with disk in raw language instead of going through file system table table and gets the list of files which are available on it. This is how some of the Data Recovery software’s will work and fetch the Shift+Deleted items for you.  Similar thing happens when you move the files (move is an operations which includes deletion at source and creation at destination if you are doing between different systems — it’s a different story when you move files within same file system). 

Well, now we know that files will still reside in disk though you permanently delete them; but for how long? Life time?. Simple answer is, “NO” not for life time. If it does like this, there won’t be any space for your new files. 

At the same, these deleted files will reside in your disk for a specific period of time. This time will be based on your system usage. If you are daily user of system and do lot of file copy stuff, your disk will end up with no free space and then it will start writing the data into the sectors where previous shift deleted items are residing. Operating System won’t mind writing the files into these locations as it sees those blocks as free space (remember when we deleted the file, it cleared the links and marked that space as free in FAT). So, when such overwrite happens, you cannot get that deleted items back. In other words, your permanently deleted data will still reside in disk until that space is used by operating system to store some other file. 

Clear? 

Now let’s take a step forward.  For some reason, you want to get deleted data back. Simply Google for recover deleted files and you will get lot many. Some of them will be free and some will charge you. Whatever is the tool, it will look for files in drive which are not part of your OS file system table to get list of deleted files. I am not sure exactly how it will be getting this list from drive, but I think drives will have some low level tables maintained for data. 

So, if the deleted files physical location is overwritten with some data by OS, can’t I get it back? 

Looks like answer is “yes” here. I read in this blog that you can recover the data which was overwritten up to 10 times. This might be dependent on your disk type as well. 

I am worried about my data confidentiality if retrieval of deleted items is possible like this.  

It’s not only you, but many organizations and individuals worry about this. So, solution here is, you should use a tool/software which completely wipes the traces of your permanently deleted data from disk.  Last month I read about such a tool named “Eraser” in TechNet Magazine(Dec-2009 edition). You might want to give a try… 

My rambling ends here…. 

Happy Learning..,
Sitaram Pamarthi

{ 0 comments }

Check for remote registry existance with Powershell

Here is a sample powershell script which helps you to check for a registry existance in remote machine.  By exploring [Microsoft.Win32.RegistryKey] API you can do much more with registry administration in powershell.

$host = “RemoteComputer”
$Hive = [Microsoft.Win32.RegistryHive]”LocalMachine”;
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive,$host);
$ref = $regKey.OpenSubKey(“SOFTWAREMicrosoftwindowsCurrentVersionUninstall”);
if (!$ref) {$false}
else {$true}

Happy Learning..,
Sitaram Pamarthi

{ 3 comments }

In this post I will explain you how to kill a sample process on remote machine using PowerShell remoting(read my previous articles in poweshell category if you want to know more about powershell remoting). I am going to kill the process, wordpad.exe on remote machine CompB using below steps.

Establish a remote session:

$remote = New-PSSession -ComputerName CompB

Bring remote commands to local session(what the heck is this?.. see powershell blog)

Import-PSSession -Session $remote -CommandName *-Process -Prefix Remote

Verify if that process exists on remote machine

Get-RemoteProcess -Name wordpad.exe

If exists, kill it..

Get-RemoteProcess -Name wordpad.exe | stop-RemoteProcess

Hmm..Check that process is terminated on remote machine.

Happy Learning..,
Sitaram Pamarthi

{ 7 comments }

In my previous post, I talked about how to enable remoting feature and testing the connection. While playing with options of remote execution of commands, I felt why should I always use a powershell window which is opened with credentials that has admin rights on remote machine. I know the admin password of remote machine and started to look for the procedure where I can make use of it and execute remote commands. Finally ended with below procedure.

I know the local administrator password of compB and I have a powershell session opened on CompA with normal rights. I used the below steps to establish a connection and execute commands.

establishing connection…

[PS] C:> $remote = New-Pssession -ComputerName CompB -Credential administrator

Executing above, prompts for password of administrator account on CompB, so please do that to proceed.

Once the connection is established, you can issue commands using the established session like shown below

[PS] C:>invoke-command $remote {Get-Process}

This displays the process of remote machine.

Once you are done with you operation, you may choose to kill that session issuing below command

[PS]C:>remove-PsSession $remote

That’s it. Enjoy remote execution…

Happy Learning..,
Sitaram Pamarthi

{ 5 comments }

GPOs and it’s enhancements (PPT)

I came across nice PPT which is explaining about today and tomorrows of Group policy infrastructure. It gives a general over view of what you can do with GPOs/GPPs in Windows 7/2008 and I felt it is useful to my blog readers; hence writing this post. You can get this presentation from this download link.

Happy Learning..,
Sitaram Pamarthi

{ 0 comments }

When a Exchange 2007 user forwards a meeting request to someone, the meeting organizer will get a Notification with subject “Meeting Forward Notification: [actual meeting subject]” saying that meeting request is forwarded to people listed in notification email body. Though Microsoft says that it is a new feature, many of the users felt it annoying. In this article I am going to talk about how to disable this behavior.

To disable this functionality for a single mailbox, use the below cmdlet

Get-MailboxCalendarSettings -Identity user1 | Set-MailboxCalendarSettings -RemoveForwardedMeetingNotifications $true

Note: You can not really disable this behavior(or I haven’t come across any such procedure), but by applying above procedure, you are making meeting request forward notification messages to go directly into “Deleted Items”.  This way users won’t get annoyed with these notification messages. Alternately,  you can configure a HTS rule to identify and drop messages with subject containing the word, “Meeting Forward Notification”.

Happy Learning..,
Sitaram Pamarthi.

{ 0 comments }

How to enable remoting in PowerShell V2

PowerShell V2 supports remote administration. That means, you can execute commands, scripts, powershell cmdlets remotely on PowerShell V2 installed computers(Windows 7 & 2008). So, in this post I am going to talk about enabling remoting feature in PowerShell V2.

It is pretty simple and straight forward process.

To enable remoting on a computer, issue the below command in powershell window

Enable-PSRemoting -force

This will configure WinRM related components and adds rules in Windows Firewall to allow WinRM communication. Once it is enabled, you can test the functionality by issuing below command.

Invoke-Command -ComputerName [remotehostname] { get-services }

The above command will display list of services available in remote machine if remoting is working on it.  You can also write your own function to test the remoting status of remote machine(one example is here )

You can invoke the execution of a batch file in remote machine and bring output to your machine by using below example.

Invoke-Command -ComputerName [remotecomp] { cmd.exe /c “c:temptest.bat” }

Hope this helped you to some extent.

Happy Learning..,
Sitaram Pamarthi

{ 0 comments }

How to delete files older than certain Days

Its general requirement and I have seen many people asking this question, “How to delete files older than given no. of days”. This can be done via various methods. If you are scripting geek, then it’s pretty easy task for you. If you are lazy/hate at scripts, then I have command for you(look at the command at bottom and use at your own risk 🙂 ).

Download the FORFILES tool from Resource Kit and frame your command. You can play around with FORFILES options to get required functionality.

Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-d<+|-><DDMMYYYY|DD>] [-s]

 -pPath               Path where to start searching
 -mSearch Mask        Search files according to <Search Mask>
 -cCommand            Command to execute on each file(s)
 -d<+|-><DDMMYYYY|DD> Select files with date >= or <=DDMMYYYY (UTC)
                      or files having date >= or <= (current date – DD days)
 -s                   Recurse directories
 -v                   Verbose mode

The following variables can be used in Command :
 @FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE,
 @FTIME

To include special hexa characters in the command line : use 0xHH

Default : <Directory : .> <Search Mask : *.*>  <Command : “CMD /C Echo @FILE”>
Examples :
FORFILES -pc: -s -m*.BAT -c”CMD /C Echo @FILE is a batch file”
FORFILES -pc: -s -m*.* -c”CMD /C if @ISDIR==TRUE echo @FILE is a directory”
FORFILES -pc: -s -m*.* -d-100 -c”CMD /C Echo @FILE : date >= 100 days”
FORFILES -pc: -s -m*.* -d-01011993 -c”CMD /C Echo @FILE is quite old!”
FORFILES -pc: -s -m*.* -c”CMD /c echo extension of @FILE is 0x22@EXT0x22

Example:  Forfiles -p “<path>” -s -m *.* -d -10 -c “Cmd /C del @FILE”

Hope this is helpful.

Happy Learning..,
Sitaram Pamarthi

{ 3 comments }

PowerShell Mobile application for Managing IT infra

Things are moving fast in PowerShell spectrum and now its the turn for mobiles. In this post, I am going to talk about a application which helps you to manage your IT infrastructure from your mobile itself. It is a web based application which you have to install in one of your corporate servers and expose it to outside world through SSL. Now connect to the published URL from your smart phone/BB and provide your domain login credentials and this gives you a powershell window from where you can run commands. Note that commands  are executed under the security context of account which you entered to authenticate.

You can find more details about this at http://dmitrysotnikov.wordpress.com/2010/01/12/mobileshell-powershell-prompt-in-a-browser/

Happy Learning..,
Sitaram Pamarthi.

{ 0 comments }

send emails via gmail account using powershell

Copy the below powershell code into a file(say send-via-gmail.ps1) and execute it from command line.

$SmtpClient = new-object system.net.mail.smtpClient
$smtpclient.Host = ‘smtp.gmail.com’
$smtpclient.Port = 587
$smtpclient.EnableSsl = $true
$smtpClient.Credentials = [Net.NetworkCredential](Get-Credential GmailUserID)
$smtpclient.Send(‘GmailUserID@gmail.com’,$args[0] ,’test subject’, ‘The mail is sent via gmail using the powershell script grabbed from https://techibee.com’)

Command to execute:

[PS]C:>.send-via-email.ps1 toemailid@todomain.com

Happy Learning..,
Sitaram Pamarthi

{ 3 comments }