Greetings,<\/p>\n
I am trying to run a script (by Ben H) that verifies if a server has a dhcp reservation. I’ve tried numerous tweaks to the script below but I cannot get it to run against the imported servers in the .csv It runs against the local machine. Any help would be appreciated.<\/p>\n
Thanks,<\/p>\n
Flynn<\/p>\n
$reserve = import-csv -path “c:\\scripts\\reservationinfo.csv” Greetings,<\/p>\n I am trying to run a script (by Ben H) that verifies if a server has a dhcp reservation. I’ve tried numerous tweaks to the script below but I cannot get it to run against the imported servers in the .csv It runs against the local machine. Any help would be appreciated.<\/p>\n Thanks,<\/p>\n Flynn<\/p>\n $reserve = import-csv -path “c:\\scripts\\reservationinfo.csv” If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>
\n$reserve | ForEach {
\n$Servers = $.Servers
\n$NetAdapters = foreach ( $i in (Get-WmiObject Win32_NetworkAdapterConfiguration -Computername $Servers) | ? {$<\/em>.DHCPEnabled -eq $True -and $null -ne $.IPAddress} ) { $i.ipaddress[0] }
\n}
\nIf ($NetAdapters) {
\nForeach ($Adapter in $NetAdapters) {
\nforeach ($ip in $i.ipaddress[0]) {
\n$Reservation = Get-DhcpServerv4Reservation -ScopeId $IP -ComputerName dhcpserver | ? {$<\/em>.ScopeId -eq $_.IPAddress}
\nIf ($Reservation) {
\nWrite-Output “$IP is reserved.”
\n} Else {
\nWrite-Output “$IP does not have a reservation.”
\n}
\n}
\n}
\n}Else {
\nWrite-Output “No DHCP Enabled NetAdapters with IPAddresses exist on host, likely Static”
\n}<\/p>","upvoteCount":2,"answerCount":6,"datePublished":"2018-03-08T16:42:37.000Z","author":{"@type":"Person","name":"flynnkeilty1382","url":"https://community.spiceworks.com/u/flynnkeilty1382"},"suggestedAnswer":[{"@type":"Answer","text":"
\n$reserve | ForEach {
\n$Servers = $.Servers
\n$NetAdapters = foreach ( $i in (Get-WmiObject Win32_NetworkAdapterConfiguration -Computername $Servers) | ? {$<\/em>.DHCPEnabled -eq $True -and $null -ne $.IPAddress} ) { $i.ipaddress[0] }
\n}
\nIf ($NetAdapters) {
\nForeach ($Adapter in $NetAdapters) {
\nforeach ($ip in $i.ipaddress[0]) {
\n$Reservation = Get-DhcpServerv4Reservation -ScopeId $IP -ComputerName dhcpserver | ? {$<\/em>.ScopeId -eq $_.IPAddress}
\nIf ($Reservation) {
\nWrite-Output “$IP is reserved.”
\n} Else {
\nWrite-Output “$IP does not have a reservation.”
\n}
\n}
\n}
\n}Else {
\nWrite-Output “No DHCP Enabled NetAdapters with IPAddresses exist on host, likely Static”
\n}<\/p>","upvoteCount":2,"datePublished":"2018-03-08T16:42:37.000Z","url":"https://community.spiceworks.com/t/run-script-on-servers-imported-from-csv/639207/1","author":{"@type":"Person","name":"flynnkeilty1382","url":"https://community.spiceworks.com/u/flynnkeilty1382"}},{"@type":"Answer","text":"