1

I am trying to enumerate a list of servers from Active Directory, and then insert the server name into a UNC path as part of a copy command.

When I execute the script, I get the result below. I think that maybe I have to convert my variable, but I am not sure what to convert it to.

VERBOSE: Performing the operation "Copy File" on target "Item: C:\davidtemp\Logo.png Destination: \@{name=NCIDITSTWEB07}\c$\program files...

$webdev = Get-ADOrganizationalUnit -filter {name -like "*dev*"} | where {$_.DistinguishedName -like "*relativity*"}
$ServerList = Get-ADComputer -SearchBase $webdev | where {$_.name -like "*web*"} | select name | sort name


Foreach($server in $ServerList)
{
$scriptBlockwork = { copy C:\davidtemp\Logo.png "\\$server\c$\program files\web\images" -Force -Verbose}
Invoke-Command -ScriptBlock $scriptBlockwork -verbose
}
dave562
  • 33
  • 4

1 Answers1

1

I reached out to a friend who was able to help. I was not defining the variable properly.

I needed to use -expandProperty to get the results into a format that worked with the pipeline

$ServerList = Get-ADComputer -SearchBase $webdev | where {$_.name -like "web"} | select -expandProperty name

Hopefully this helps someone else who might be having a similar issue.

dave562
  • 33
  • 4