Professional Geek
RSS icon Email icon Bullet (black)
  • Backup Sharepoint Document Library

    Don’t get all excited. This isn’t going to be anything too clever but i thought i’d share it anyway

    One of our clients uses WSS (v2) in conjunction with InfoPath to do their timesheets.

    We were asked how you would go about recovering the timesheets from a backup.

    I explained that we’d probably have to restore the site to a temporary site then move the files we needed from the restored document library to where it belongs (if someone knows an easier way please let me know?!)

    The client wanted to know if there was an easier way of doing this so i came up with a vbscript that grabs all the xml files and copies them to a folder. As i said at the start, this solution isn’t clever so if your looking to use this to backup other document types (word documents for example) it’s not going to bring any of the metadata with it

    The script connects to the document library via a UNC path and just treats it like a file share

    For this to work you need to make sure the WebClient service is running (if you get an error message that says something like “workstation driver is not installed” just restart the computer and you’ll be fine)

    If your going to schedule this you should probably add some code that maps a network drive to the share instead of accessing the UNC directly (only way i can think of passing credentials?)

    So heres the script….

    Dim myFSODim DocLib
    
    Dim TimeSheet
    
    Dim BackupTo
    
    Dim dayWeek
    
    Dim FullDay
    
    Dim LibraryPath
    
    Dim BackupPath
    
     'Setup Variables
    
    'Ensure BackupPath ends with a \
    
    LibraryPath="\\companyweb\TimeSheets"
    
    BackupPath="E:\Time Sheet Backups\"
    
    dayWeek = DatePart("w", (Date))
    
    Select Case dayWeek
    
    Case 1
    
        FullDay = "Sunday"
    
    Case 2
    
        FullDay = "Monday"
    
    Case 3
    
        FullDay = "Tuesday"
    
    Case 4
    
        FullDay = "Wednesday"
    
    Case 5
    
        FullDay = "Thursday"
    
    Case 6
    
        FullDay = "Friday"
    
    Case 7
    
        FullDay = "Saturday"
    
    End Select
    
    Set myFSO = CreateObject("Scripting.FileSystemObject")
    
    Set DocLib = myFSO.GetFolder(LibraryPath)
    
    Set BackupTo = myFSO.GetFolder(BackupPath & FullDay)
    
    myFSO.DeleteFile BackupTo.Path & "\*.*"
    
    For Each TimeSheet In DocLib.Files
    
    TimeSheet.Copy BackupTo.Path & "\" & TimeSheet.Name
    
    Next
  • Long live vbscript

    I know Powershell is the next best thing in scripting but i’m still a big VBScript fan. There are lots of resources for helping you create powerful scripts

    I spotted the following on the Microsoft Download site

    Enough reading there to keep you going for a while!

  • Change Mail Redirection in VBScript – Exchange 2003

    Was doing some housekeeping and came across a script i thought i’d share

    We had a customer who had a general information style email address (info@blahdomain.com) that due to job sharing two different people were responsible for checking the email and replying. To add to this these people were external to the organisation. They wanted the email to be re-directed to their own email addresses (i did suggest that they just use Outlook Web Access and share a mailbox but they weren’t interested!)

    So i created two external contacts and re-directed the email to the user. However this wasn’t something i wanted to be doing myself a couple of times as week as the responsibility changed and i didn’t trust the users!

    So i created a script that ran on a scheduled task to make the change. I found it incredibily difficult to find anything out about this method at the time so here it is
    ‘ Change this name to alter re-direction
    strUserName=”Parkesy”

    Set objUser = GetObject (“LDAP://cn=INFOUSER,ou=AP Users,dc=blahdomain,dc=local”)
    objUser.Put “altRecipient”, “cn=” & strUserName & “,ou=AP Users,dc=blahdomain,dc=local”
    objUser.Put “DeliverandRedirect”, True
    objUser.SetInfo

    I’ve trimmed the code down for display but all it does is find the “Info User”, reset the “Alt Recipient” and “Deliver and Redirect” properties, and persist the changes 

    I created two copies of this and setup a scheduled task to make the switch

    It seemed to work quite well but eventually the stopped the job share and it became an internal users responsibility and the script got “retired”

    Hope it is of use to someone else

    I used this script on an Exchange 2003 box. I haven’t tested it on an Exchange 2000 box but can’t see an inital reason for it not to.

    Use the code as you see fit but i take no responsibility for anything that may occur due to it’s usage (blah blah blah!)

    *-* Slight Update *-*

    Going through some posts i hadn’t gotten around to reading and saw this post from Dave Overton which links to a tutorial on MSExchange.org which talks about how to set all this up. My post assumes this is all in place

  • Useful Scripting Resource

    I posted a while back on how useful scripting is so i thought i’d share a useful resource i found yesterday

    “Hey Scripting Guy” is a very useful (and entertaining) column on the Microsoft Script Centre. What makes this particular column great (in my opinion) is that a question for a specific problem is answered in great depth with lots of examples and pointers for any “gotcha’s” that might trip you up

    So anyway enough brown-nosing, i found out yesterday that you can download their archive as a complied html help document (here)

    Articles are grouped into categories with the added bonus of being able to search for exactly what you need.

    Go get it!

  • Scripts are your friends

    Just reading a post from the “Addicted to IT” blog

    Why SBSers should be writing more scripts!

    The gist of the article is that you don’t need to be a programmer to create scripts and they are so useful that they can help out in all sorts of different ways

    Have to say i complety agree on this one. I do have a slight advantage in that i do have some programming experience (which i’ll post about some other time) but to create scripts (vb or js) isn’t difficult. They are so many resources to get you started and the examples on the Microsoft script centre sometimes means you don’t actually need to write anything..cos it’s already been done for you!

    The post also goes on to talk about re-using scripts.

    This is something i do a lot. I’ll write a script for a specific task then a some point in the future i’ll grap parts of it so dont have to waste time figuring it all out again. For example i was having a problem with a script that copies data from one server to another so created a logging function. Now i drop that code in every new script so i get more detail on whats happening!

    The more scripts you create the easier it gets as you can reuse parts over and over again!

    I have a SharePoint list that i keep all my scripts in. This lets me search for specific tasks. When i get around to it i’ll maybe categorise them for easier access

    Scripts are very powerful and can make lots of boring repetitive tasks nice and easy 

    Visit the Microsoft Script Center and get started!

  • Doh!

    Ever feel stupid?

    I have a vbscript that copies a series of files from one server to another (don’t ask why!) that runs using a scheduled task

    Now if i run the script manually all works fine. If i run the scheduled task manually all works fine.

    However, every week when i expect the data to have been copied nothing happens

    I’ve simplified the code for posting purposes as the code also does some logging and error checking

    SourceFolderPath = “S:\Images\System\”
    DestinationFolderPath =”E:\images\TempArea\” 

    set FSO = CreateObject(“Scripting.FileSystemObject”)

    set SourceFolderObj = FSO.GetFolder(SourceFolderPath)
    Set DestinationFolderObj = FSO.GetFolder(DestinationFolderPath)
    ”Empty Destination Directory

    For each LoopFile in DestinationFolderObj.Files
    LoopName = LoopFile.name
    LoopFile.Delete
    next

     ”Transfer files

    For each LoopFile in SourceFolderObj.Files

    LoopFile.Copy(DestinationFolderPath)

    Next

    Can anyone tell me why this fails?

    I had a eureka moment this morning

    The source folder is on drive S:

    Which exists when i run the script manually. But it doesn’t exist when i’m logged off

    So i added the following

    strDriveLetter = “S:”
    strRemotePath = “\\Server\Share
    strUser = “someuser”
    strPassword = “somepassword”    Â
    strProfile = “false”

    Set objNetwork = WScript.CreateObject(“WScript.Network”)
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath,strProfile, strUser, strPassword

    And volia!

    Not entirely sure why i didn’t spot this earlier but needless to say when i did i felt like giving myself a kick!