Question

Write power shell function/script to let the user know the state of ipv4 address on the...

  1. Write power shell function/script to let the user know the state of ipv4 address on the computer (state can be static or dynamic IP). If it is static IP address, request user input if he/she wishes to change state to dynamic, if answer is “Y”, change ipv4 address to dynamic IP.
    If the current state is dynamic, ask the user if he/she wishes to change status to static IP, if user decides change the state to static, and request for the static IP address, net mask, DNS and default gateway; set the new information on ipv4 interface ass given.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

To know whether the ip address is static or dynamic just run the following powershell script.

Get -WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName.

This script will give the following details

DHCPEnabled : True or False

IPAddress: : {192.168.168.174,192.168.1.155,10.10.12.89, fe80::c994:2b82:e28c:b672}.

DefaultIPGateway , DNSDomain and ServiceName etc.

In these details if you found DHCPEnabled as "TRUE" then it is "Dynamic IP"

if you found DHCPEnabled as "FALSE" then it is "Static IP"

If you found DHCPEnabled as False then ask user whether he wants to change it to Dynamic using following script.

$toChange= Read-Host 'Enter Y to change it to Dynamic IP?'

PowerShell Script to change from StaticIP to DynamicIP

if ($toChange -eq 'Y'){

$NICs=Get -WMIObject Win32_NetworkAdapterConfiguration `

| where {$_.IPEnabled -eq "TRUE"}

Foreach($NIC in $NICs) {

$NIC.EnableDHCP()

$NIC.SetDNSServerSearchOrder()

}

}

PowerShell Script to change from DynamicIP to StaticIP:

$ipaddress= Read-Host 'Enter IPAddress'

$mask= Read-Host 'Enter Subnet Mask'

$gateWay=Read-Host 'Enter GateWay'

$dnsServer= Read-Host 'Enter DNSServers'

$NICs=Get -WMIObject Win32_NetworkAdapterConfiguration `

| where{$_.IPEnabled -eq "TRUE"}

Foreach($NIC in $NICs){

$NIC.EnableStatic($ipaddress,$mask)

$NIC.SetGateWays($gateWay)

$DNSServers=$dnsServer

$NIC.SetDNSServerSearchOrder($DNSServers)

$NIC.SetDynamicDNSRegistration("FALSE")

}

Add a comment
Know the answer?
Add Answer to:
Write power shell function/script to let the user know the state of ipv4 address on the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • LINUX question Write a shell script called findcapital to find the capital of a state, given...

    LINUX question Write a shell script called findcapital to find the capital of a state, given the state. Create a function called read_state that reads your capitals file into an array. Create another function called find_it that checks if the user's inputted state matches one of the elements in the array. It matches, tell the user the capital. The main part of the program will execute the read_states function, get the input, then execute the find_it function. Add the following...

  • use TOLEDO OHIO USA IP ADDRESS and typed please! 1 of 1 Environment variables are some of the most useful tools avai...

    use TOLEDO OHIO USA IP ADDRESS and typed please! 1 of 1 Environment variables are some of the most useful tools available to command shell script writers. By default, all Windows systems include a host of environment variables that can provide important information about the system and the current user a Run ipconfig /all in the command line. What is your computer's running Ipv6 address? 2) To list all your system's environment variables, you can type "set". What the COMPUTERNAME...

  • In Chapter 1, “Analyzing Business Goals and Constraints,” you first learned about ElectroMyCycle, a manufacturer of...

    In Chapter 1, “Analyzing Business Goals and Constraints,” you first learned about ElectroMyCycle, a manufacturer of electric motorcycles. Now, ElectroMyCycle has chosen you to design a new network that will let the company scale to a larger size. In Chapter 5, you learned that ElectroMyCycle’s network will support about 200 employees. The network will include a data center and a new state-of-the-art manufacturing facility. Users in the campus network will access the servers in the data center from their PCs....

  • i have the case study question with the answers but i need help to re-write the...

    i have the case study question with the answers but i need help to re-write the answers. please see the attached files Case Study Analysis (CSF3003) Assessment Description and Requirements CLO1: Case Study 1 Ahmad lef home to study master and PhD in Australia. He has fees for the first semester only. After he arrived to Sydney and settled down, he start looking for a part-time job to save money for the next term. Ahmad has some experience on making...

  • Write down your analysis of this case on factors like the interests involved, context and power...

    Write down your analysis of this case on factors like the interests involved, context and power PACIFIC OIL COMPANY (A)* "Look, you asked for my advice, and I gave it to you," Frank Kelsey said. "If I were you, I wouldn't make any more concessions! I really don't think you ought to agree to their last demand! But you're the one who has to live with the contract, not me!" Static on the transatlantic telephone connection obscured Jean Fontaine's reply....

  • Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of...

    Using the book, write another paragraph or two: write 170 words: Q: Compare the assumptions of physician-centered and collaborative communication. How is the caregiver’s role different in each model? How is the patient’s role different? Answer: Physical-centered communication involves the specialists taking control of the conversation. They decide on the topics of discussion and when to end the process. The patient responds to the issues raised by the caregiver and acts accordingly. On the other hand, Collaborative communication involves a...

  • How can we assess whether a project is a success or a failure? This case presents...

    How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...

  • Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around...

    Risk management in Information Security today Everyday information security professionals are bombarded with marketing messages around risk and threat management, fostering an environment in which objectives seem clear: manage risk, manage threat, stop attacks, identify attackers. These objectives aren't wrong, but they are fundamentally misleading.In this session we'll examine the state of the information security industry in order to understand how the current climate fails to address the true needs of the business. We'll use those lessons as a foundation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT