So this little how-to relates to Swiftpage Act! Pro (CRM software) but may be applicable to other cases.
Act! is able to store shortcuts to files and folders for each contact to facilitate access to those locations. These shortcuts could point to documents or spreadsheets (or any other type of file) on a Windows Share, making them accessible in a multi-user Act! environment. But what if you ever wanted to move those files to a different location? The problem, of course, is that you break all of the shortcuts because the file locations have changed. We can use Powershell to programmatically fix this.
This first step is to determine where the shortcuts are stored in the Act! file structure and that varies according to the OS.
$thisos = [System.Environment]::OSVersion.Version.Major
if ($thisos -eq 10) {
$thishome = $env:APPDATA
} elseif ($thisos -eq 6) {
$thishome = $env:homedrive + $env:homepath + "\Documents"
} else {
# not Windows 10 or Windows 7
$thishome = "\path\to\folder"
}
A standard installation of Act! will use this root ($thishome) for its user files and create the following directories under it.
\Act\Act Data\(dbname)-database files\
Subdirectories for Attachments, Reports, Queries, Layouts, Templates and a few others would then be found under that. The Act! link or shortcut files will be placed in the Attachments directory.
When we move the files to their new location, the shortcuts become invalid. We can walk through those links and adjust them as necessary.
$from = "\\oldstorage\"
$to = "\\newstorage\"
$files = "*.lnk"
$dbloc = "\ACT\Act Data\Databases\mydb-database files"
$folder = $thishome + $dbloc + "\Attachments\*"
$list = Get-ChildItem -Path $folder -Include $files
ForEach($lnk in $list) {
$obj = New-Object -ComObject WScript.Shell
$link = $obj.CreateShortcut($lnk)
$path = $link.TargetPath
$oldpath = $path
$newpath = $path.Replace($from.tostring(),$to.ToString())
if($newpath -ne $oldpath) {
#-----------------------------------------------
# Update the target path and save the shortcut
#-----------------------------------------------
$link.TargetPath = $newpath
$link.Save()
}
}
The $from and $to represent what is changing in the link. In this simple example, we are retaining the file structure but modifying the storage container “Share” name.
You would need a modified approach to this if your Act! installations deviate from the default locations, but this should still give you a general idea of the things that need to be done.
I like to use Visual Studio Code with the Powershell extension to develop my scripts, but any text editor will do the job.
Remember to test in Test before executing in Prod. You know what I mean.
Leave a comment