Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell - find if a value is present

$
0
0

Hi,

I'm writing a DHCP migration tool in powershel, but struggling with one of the options. Here is the scenario:

I want to copy over all server option from the source server to the destination server. So I can use these commands

Get-DhcpServerv4OptionDefinition -ComputerName 

and

Add-DhcpServerv4OptionDefinition -ComputerName 

The issue with this is that if most of the server options are standard and cause an error when I run it like this

Get-DhcpServerv4OptionDefinition -ComputerName source-servername | Get-DhcpServerv4OptionDefinition -ComputerName dest-servername

the error is the value already exists.

So what I am trying to do is for each dhcp option in the source server, check if it exists in the desitnation server, and if it doesn't add it.

the value of the commands display like this

Name                 OptionId             Type                 VendorClass          MultiValued        

----                 --------             ----                 -----------          -----------        

Classless Static ... 121                  BinaryData                                False              

Subnet Mask          1                    IPv4Address                               False              

Time Offset          2                    DWord                                     False              

Router               3                    IPv4Address                               True               

Time Server          4                    IPv4Address                               True               

Name Servers         5                    IPv4Address                               True               

DNS Servers          6                    IPv4Address                               True               

Any ideas on the best way to code this? Im trying with if statements and -contains but not having a great deal of luck.


Regards,

Denis Cooper

MCITP EA - MCT

Help keep the forums tidy, if this has helped please mark it as an answer

My Blog

LinkedIn:


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>