none
Script to search for a file for multiple domain controllers RRS feed

  • Question

  • Hello, 

    I'm in the process of updating FRS to DFSR on 47 domain controllers. I'm trying to write a script to search for this file on each domain controller (c:\windows\sysvol\sysvol\reedsmith.com\replication.txt)

    I have a CSV with one column that contains the server name. I'm unable to get this script to work. Can anyone advise on what could be the issue? The script is below, and the error message is below the script. 

    Script: 

    Import-Csv "h:\temp\dclist.csv " | Foreach {
    $server = $_.servername
    $path = "c:\windows\sysvol\sysvol\reedsmith.com"
    $file = “Replicationtest.txt”

    Get-ChildItem -Path $path -Include $file -Recurse -ErrorAction SilentlyContinue  -Force |  

    Select-Object $server, $file }

    Error message: 

    Select-Object : The value of a parameter was null; one of the following types was expected: {System.String, 

    System.Management.Automation.ScriptBlock}.
    At line:8 char:1
    + Select-Object $server, $file }
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException
        + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
    Select-Object : The value of a parameter was null; one of the following types was expected: {System.String, 
    System.Management.Automation.ScriptBlock}.
    At line:8 char:1
    + Select-Object $server, $file }

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:43 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, September 11, 2018 2:26 PM

All replies

  • See: help select-object -online

    Follow the instructions.


    \_(ツ)_/

    Tuesday, September 11, 2018 2:42 PM
  • If you know the path and it is only this one file and you have access to the servers you could try this ....
    Import-Csv "h:\temp\dclist.csv " | 
        ForEach-Object {
            $path = '\\' + "$_.servername" '\c$\windows\sysvol\sysvol\reedsmith.com\Replicationtest.txt'
            [PSCustomObject]@{
                Server = $_.servername
                FileExist = Test-Path -Path $path
            }
        }

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Tuesday, September 11, 2018 2:44 PM