SCAPaoT

System Center, Automation, Powershell and other Thoughts

Tag Archives

DFSR: Powershell script for removing “temporary file” flag to replicate a file

At a customer we decided to remove the need of backing up files in the branches, so theres no need for the employees to switch tapes or usb drives.
To get all data backed up nevertheless, we implemented DFSR between the branches and the head quarter. In the head quarter the data are backed up.

A quick look in the DFSR reportings showed up, that there are files, that where not backed up.

With a little search in a famous serach engine, we stumbled throughwards that blog:
http://blogs.technet.com/b/askds/archive/2008/11/11/dfsr-does-not-replicate-temporary-files.aspx

At the customer, there are some scanning devices responsible to convert all paper mail into digital files. Those devices are generating its output directly on the file server.
All files generated that way do not loose the temporary file attribute after saving the file.

So we buidled a powershell script that run’s as scheduler to remove these flags on a daily base.

If you are interested in this on,

here you are:


<#

.SYNOPSIS
This script is for determing files with  "Temporary File" attribute set.

.DESCRIPTION
The script shows files where the "Temporary File"-attribute is set. Those files are not synchronised by Microsoft DFSR.
Also the script can remove the attribute, based on the file extension.
The common extensions are a set as default, but can be overridden by command.

.PARAMETER startpath
    Specifies the file path to start the search for files with "Temp File"-attribute set.

    Required?                    true
    Default value
    Accept pipeline input?       false

.PARAMETER RemoveTemp
    If this switch is used, the "Temp File"-attribute is removed from the file.

    Required?                    false
    Default value
    Accept pipeline input?       false
.PARAMETER extensions
    Specifies the file extensions that should be inspected.

    Required?                    false
    Default value   (".pdf",".xls",".doc",".docx",".xlsx",".ppt",".pptx",".bmp",".jpg")
    Accept pipeline input?       false

.PARAMETER countOlny
    If given, only the count of the affected file is shown.

    Required?                    false
    Default value  
    Accept pipeline input?       false

.EXAMPLE
.\tempfiles.ps1 -startpath D:\

This Example lists the files where the "Temp File"-attribute is set located on the hole D:\ - Drive

.EXAMPLE
.\tempfiles.ps1 -startpath D:\ -removeTemp

This Example lists the files where the "Temp File"-attribute is set and removes the "Temp File"-attribute.

.EXAMPLE
.\tempfiles.ps1 -startpath D:\ -removeTemp -extensions ".exe",".jpg"

This Example lists the files where the "Temp File"-attribute is set if the file extension is exe or jpg only.
.NOTES
See Link for further description.

.LINK

<a href="http://blogs.technet.com/b/askds/archive/2008/11/11/dfsr-does-not-replicate-temporary-files.aspx">http://blogs.technet.com/b/askds/archive/2008/11/11/dfsr-does-not-replicate-temporary-files.aspx</a>

#>

param([string]$startpath=(read-host "Start Pfad"),[switch]$removeTemp,[string[]]$extensions=(".pdf",".xls",".doc",".docx",".xlsx",".ppt",".pptx",".bmp",".jpg"),[switch]$countOnly)

if(!($startpath -eq ""))
{
if(test-path -path "$startpath" -ErrorAction SilentlyContinue)
{
if(!($countonly))
{
Get-childitem $startpath -recurse | `
ForEach-Object {
 if (($_.attributes -band 0x100) -eq 0x100)
 {
  
  foreach($ext in $extensions)
  {
  if($_.extension.tolower() -eq $ext.tolower())
   {
    $_.fullname
  
    if($removetemp)
    {
     $_.attributes = ($_.attributes -band 0xFEFF)
    }
   break
   }
  }
 }
}
}
else
{
$count = @(Get-childitem $startpath -recurse | where-object { $_.attributes -band 0x100 }).count
"There are $count files affected in $startpath with seleted extensions: `"$extensions`""
}
}
else
{
"Path $startpath not found!"
}
}
else
{
 get-help .\tempfiles
}

DfsDnsConfig also under Server 2008 R2

Since DFS Namespaces are available in Windwos 2000, clients get the referrals to the linked shares with the netbios name instead of the FQDN of a fileserver.
In Server 2008 R2 nothing was changed. So clients get the referall with only the netbios-name of the server.

In time where Microsoft wants WINS to die, why don’t they change that?

Getting the netbios instead of the FQDN of a server doesn’t make any problems when all your systems work in just a single active directory domain.
But if you need to gain access from outside the domain where the dfsroot is in, then using only the netbiosname can make a problem.

Two possible solutions are:
1. Add the dns suffix to the suffix search list, so it will try accessing the netbios name with the dns suffix attached if the netbios name isn’t found.
This has to be done on every client. It can be done by GPO or DHCP to not to touch all clients)

2. This is the one I preferr:
At a Registy key to the server that will be the root server for the namespace.
If the server already is a namespace server. you have to remove the root before setting the key.
The value is DfsDnsConfig = 1 (dWord) under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Dfs

All DFS-Namespaces have to be build up again. For that you can export the namespace with dfsutli, change all netbios names into FQDN’s and import it back.

Read this KB article also:http://support.microsoft.com/kb/244380/en-us