title: Help on getting started with powershell - rewrite an old BAT + SQL file
body: <p>I'm totally new to powershell, and I need some help to get started.
  What I need is to write a small script that backup a SQL database, but every time with different name (to keep the last 4-5 versions only).
  Right now I have a BAT, which just launch osql with a sql script, as below</p>
  
  <pre><code>REM BAT file starts here
  "C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -S myServer -E -iC:\Scripts\backupDB.sql
  </code></pre>
  
  <p>And the backup script is </p>
  
  <pre><code>BACKUP DATABASE [MyDB] TO  DISK = N'C:\Backup\MyDB.bak' WITH NOFORMAT, INIT,  NAME = N'MyDB-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
  GO
  </code></pre>
  
  <p>This BAT is run by task scheduler. Obvious, it does not creates different DB backup files.
  What I would like is to replace the whole thing with a powershell script, which will look in target directory and keep only last N backup files (starting from the newest one), then generate a backup filename like</p>
  
  <pre><code>MyDB-yy.mmdd.hhmmss.bak 
  </code></pre>
  
  <p>and backup in that.</p>
  
  <p>I could create a simple C# console application to do that, but I would like to start playing and testing with Powershell.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thank you</p>