Hi,
Apologies in advance, I’m somewhat green when it comes to scripting!
I’m hoping someone can point me in the right direction or offer some advice on the below. I’m trying to set IIS bindings on multiple web servers, remotely. The challenge is that I can’t get my head around the Using scope modifier (or I may be way off the mark!), in order to pass the right variables to New-WebBinding. So right now I’m copying CSV files to each web server in the below as a work around.
$servers = Get-Content "\\FQDN\servers.txt" ForEach ($server in $servers) { New-Item -Path \\$server\c$\temp\bind -ItemType Directory Copy-Item -Path "\\FQDN\$server.csv" -Destination \\$server\c$\temp\bind Invoke-Command -ComputerName $server -scriptblock { Import-Module WebAdministration Remove-WebBinding Import-Csv c:\temp\bind\$env:computername.domain.csv | ForEach-Object { $site = $_.Site $prot = $_.Protocol $IP = $_.IPAddress $Port = $_.Port New-WebBinding -Name $site -IPAddress $IP -Port $Port -Protocol $prot } } Remove-Item \\$server\c$\temp\bind -force -recurse }
Any help gratefully received and thanks!
James