I'm in a small business environment (Win 7 Pro 64 workgroup, single LAN) where I would like to be able to run a script that would make a link on the local machine to a folder on our NAS, copy system restore files, then remove the link. The objective is to isolate system restores as an added layer of protection, this process ideally includes severing direct links to the NAS from any user machine unless copying these files.
I have already allowed access to the System Volume Information folder for my account.
Searches have found a lot of posts about scripts with mklink, but I couldn't find a solid example of what I wanted and the languages I've seen used range from bash to Powershell.
I have scripted a lot in VBA but not with Powershell or even much in VBScript, which language is most appropriate for this? If Powershell I'm going to have to install it on the Win 7 machines, not a huge deal. VBScript or batch would be the easiest for me to write and distribute. I also have perl installed on my machine but would have to install it on a handful of other machines.
My first question is: which language would be best in this situation? I would prefer VBScript or batch if possible, or Powershell. perl if necessary.
Second question: can someone give me an example script? Typical mklink command looks like this (from what I understand):
mklink /d :name: :target:
Should I use the /j flag instead of /d ? Should I mount the drive (I'm unclear on how to do this with Windows CLI or Powershell)?
Also if this will not work in the first place feel free to let me know. Thanks.
So you could do this with PowerShell easily enough. You would not use MKLink, but would create a temporary mapping to the NAS location (been several years since I worked with a real NAS, I'm hoping that I remember right and that they do in fact have a UNC path such as \NAS01\Share). So you would use New-PSDrive, and just not use the -Persistent parameter, so the connection would end when the script ended and the PowerShell session exited. Then you can copy files as needed. In fact, you could set it to check all the files in both locations and only upload files that are updated locally. So assuming you have a folder for each computer to be backed up created on the share you could do this:
New-PSDrive -Name NAS -Root \\NAS01\Share\$env:COMPUTERNAME -PSProvider FileSystem
$Source = 'C:\System Volume Information'
Compare-Object (Get-ChildItem $Source -Recurse) (Get-ChildItem 'NAS' -Recurse) -PassThru |
Where{$_.SideIndicator -eq "<="} | ForEach{Copy-Item $_.FullName -Destination ($_.FullName -Replace [regex]::escape($source), 'NAS:')}
That essentially creates a drive named NAS that's mapped to the network path described, and then pulls a directory listing for both locations, and for items that are in the source that are not in the destination it copies it to the destination. Once the script is finished running PowerShell should exit and remove the link to the NAS when it does.