Finding all sage company files and listing the company name they relate to.

Sage is a pain to administer. If you have to look after a sage installation with hundreds of companies on a network share (or, worse, scattered everywhere) then you may have wished for an easy way to find or list every sage company folder and the company name that resides within in.

Sage don’t provide an easy way to do this. They give you a list of the companies already added to a sage installation but quite often not every sage folder has been added to the sage program’s list.

The script I’ve mashed up creates a report of every sage file found within a folder and it’s subfolders (or an entire disk drive if you start the script from within the root) and outputs it to screen and to a file.

Before running – make sure you’ve put the Strings executable in the windows system32 folder (or some other folder and then change the strings path to point directly at it).
Then run the strings command from powershell or command prompt so you can then press Accept on the terms.

Get-ChildItem -Recurse -filter setup.dta | foreach-object {
  if ($_.FullName.contains("ARCHIVES") -eq $False) {
    $myCompanyName = strings -b 64 -nobanner $_.FullName
    $myCompanyFile = $_.FullName.replace("C:\Shares\sage\", "")
    $myCompanyFile = $myCompanyFile.replace("\SETUP.DTA", "")
    $myCompanyFile + ': ' + $myCompanyName
    $myCompanyFile + ': ' + $myCompanyName | Add-Content -Path c:\temp\SageList.txt

The above powershell code can be pasted in or run as a powershell script (.ps1) and searches any subfolders, starting from the directory you “cd” to before running it, for Sage data files and then uses the Strings command from SysInternals to spit out the company name.

It also writes the results to c:\temp (make sure the directory exists, or modify the path in the script if you want it to output elsewhere).

I’m no expert in powershell scripting so if you have any comments or improvements, please leave a message below the article.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Finding all sage company files and listing the company name they relate to.

  1. David Casey says:

    Thanks for posting, that will come in handy.

  2. Not sure when it got corrupted but for the last few days the script had " in instead of just ”
    This has been corrected. I’ve also removed one of the specific replace lines with c:\shares which is probably only useful if you had the same folder structure as the system I was running the script on.

Comment on this topic

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s