Automating backup of databases in SQL Express.

Posted by Alesandro Slepčević | Posted in Servers, Windows and Powershell | Posted on 22-11-2009

0

mssql-logoMicrosoft SQL Server 2005/2008 Express is a free edition of SQL Server that is ideal for learning, developing and powering desktop, web and small server applications, and for redistribution by ISVs.

Top Features

  • Supports stored procedures, triggers, functions, and views
  • Store all kinds of business data with native support for relational data, XML, FILESTREAM and spatial data
  • Improved performance, usability, visualization, in addition to integration with the Microsoft 2007 Office System in SQL Server Reporting Services
  • Simplify development efforts by leveraging existing T-SQL skills, ADO.NET Entity Framework and LINQ
  • Closely integrated with Visual Studio and Visual Web Developer

Because there’s no “SQL Agent” in SQL Express Editions, in order to create scheduled backups on SQL server Express edition, we need to user couple of tricks  :)

Powershell cheat sheet :)

Posted by Alesandro Slepčević | Posted in Windows and Powershell | Posted on 20-10-2009

1

Surfing all over the net, I found a very handy powershell cheat sheet that was put together by Ben Pearce. Anyways, here’s the download link (just click on the picture).

cheatsheet

Big hello to the guys from www.bug.hr :)

Add new ip or ip range to firewall rule using Powershell

Posted by Alesandro Slepčević | Posted in Servers, Windows and Powershell | Posted on 14-10-2009

0

firewalljpg

Tired of old point and click interface? :) Powershell is the new purple in computer world :) haha…Seriously! :)

So, here’s a little script that will add the Ip address you want to the existing firewall rule.

As you can see, it fairly simple, and there’s no need to explain it too much….


Function IP
{
param ($ipadress = $(Read-host "Enter IP address"))
$rule = "YOUR PREVIOUSLY CREATED RULE NAME"
Write-host "Adding address :" $ipadress -foregroundcolor "Red"
Start-sleep -s 5
netsh advfirewall firewall set rule name="$rule" new remoteip="$ipadress" action="allow"
}
IP

Only thing you have to do in the script is to enter your fireall rule name.

When you start the script, it  will ask you to enter desired ip address, and press enter. After that, wait 5 seconds and thats it :)

Cheers!

Delete files older than…. in Powershell

Posted by Alesandro Slepčević | Posted in Windows and Powershell | Posted on 01-10-2009

5

delete_key_eraser_inhandRecently I’ve found myself in a situation where I had to periodically delete files older than 7 days. I could have done it manually, but being busy, I often forgot to do it. The script I’m about to show you is a bit modified than the original, but, the principle is the same. Here I’ve added a posibilty to manually enter the directory name. In your script, you can define it, so it is being run automatically, without your intervention.

Here’s the code :

Function GetOldFile
{
param ($Dir = $(Read-host "Unesi putanju do direktorija")),
($Days = $(Read-Host "Brišem fileove starije od koliko dana?"))
$TargetFolder = $Dir
if (Test-Path $TargetFolder)

{
Write-host "DIREKTORIJ JE :" $TargetFolder -foregroundcolor "Red"
#Write-Host `a `a `a `a `a - odkomentirati ako zelimo da pc speaker vristi :)
Write-Host "UPS, krivi folder! Stisni 'Ctrl + C' za prekid - imas 5 sekundi za prekid" -foregroundcolor "Yellow"
Start-sleep -s 5
$Now = Get-Date
$LastWrite = $Now.AddDays(-$days)
$Files = get-childitem $TargetFolder -include *.log -recurse |Where {$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{write-host "Brišem file $File" -foregroundcolor "Red"; Remove-Item $File | out-null}
}
Else
{Write-Host "Direktorij $TargetFolder ne postoji! Provjeri path!"}
}
GetOldFile

The questions in the script are in Croatian, but anyone with a little bit of programming experience will be able to change it, because the script is pretty straight forward. But, if you’re lazy as most of us are, here is the translated script :)

Powershell CAT and GREP-like stuff!

Posted by Alesandro Slepčević | Posted in Windows and Powershell | Posted on 30-09-2009

1

cat1Working as a Windows server administrator many times I found myself in a situation where I have to check 50+ Mb log file for only one e-mail address or some other term. Ofcourse, many of you are going to think: “Yeah, like that’s a problem, just press CRTL+F and type in the term :) ” ,and you’re right. That way rocks when you have 10, or maximum 20 entries where that term is mentioned ( i.e some e-mail address) in the entire log file .  But, what to do when you’re in a situation that a client wants to see the logs for his entire domain. All sent e-mail, all incoming e-mail, everything…then, it gets a little too much to do “crtl+f”  and copy/paste the result in some other file which you are going to send to the client.  Linux users have their way to do that, simply by : cat filename.txt | grep term > outputfile.txt .  By starting to explore powershell, my first task was to find a similar command to do the same thing on a Windows server. Doing a little searching on the web I found the solution that is really simple and similar to linux command :) hooray for me :)