Scan IP range then copy files to specific computers

Welcome Forums General PowerShell Q&A Scan IP range then copy files to specific computers

This topic contains 3 replies, has 3 voices, and was last updated by

3 years, 8 months ago.

  • Author
  • #24929

    Points: 0
    Rank: Member

    Here is what I need and we have pieces of it but can't get them all to fit. We need to scan an IP range (ie — to Need to find all the machine that are named starting with WIN- (generic Microsoft name after syspreping) and/or are in the workgroup not a domain. Most of that we have but to copy a file to the workgroup computers we need to use the local account which means each machine will have a WIN-NAME\ADMIN then the password for that account. What is the best way to pull the HOSTNAMES for those computers and input them in the credentials ( HOSTNAME\ADMIN ). The end result is that we need to copy a new FOG config file over to them so they will automatically add themselves to the domain and change their hostnames according to what we have in FOG. Yes this can be done in the original FOG image but at this time the main office only wants ONE fog image for everyone to keep things clean and neat so the FOG IP in the image does not point to the FOG Deployment box we are using at different locations. Really appreciate any help with this.

  • #24930

    Points: 40
    Team Member
    Rank: Member

    Hey there Shane,

    Just out of curiousity, are these machines registering their names in DNS anywhere?

  • #24931

    Points: 0
    Rank: Member

    They don't seem to be registered with DNS because I can ping a test box with the WIN- name by IP but I can not get to it by HostName.

  • #24963

    Points: 41
    Rank: Member

    You could use a nested foreach to check the ranges, something like this:

    $octet3 = 100..105
    $octet4 = 1..254
    foreach ($octeta in $octet3) {
        foreach ($octetb in $octet4) {
            if (Test-Connection "10.60.$octeta.$octetb" -Count 1 -Quiet) { 
                try {
                    $hostname = Get-WmiObject Win32_ComputerSystem -ComputerName "10.60.$octeta.$octetb" -ErrorAction Stop  | Select-Object -ExpandProperty Name
                    if ($hostname -like 'WIN*') {
                        $username = "$hostname\admin"
                        Write-Output $username
                    } #endif
                }#end try
                catch {
                    Write-Warning 'Could not get Computer Name for IP address: "10.60.$octeta.$octetb"'
                } #end catch
            } #end if
        } #end foreach
    } #end foreach

The topic ‘Scan IP range then copy files to specific computers’ is closed to new replies.