# How do you get a script to start again from the top?

**URL:** <https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863>\
**Category:** PowerShell Help\
**Created:** [September 7, 2013, 11:28pm UTC](https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863 "2013-09-07T23:28:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![barry-thomson](https://avatars.discourse-cdn.com/v4/letter/b/ecb155/32.png) [@barry-thomson](https://forums.powershell.org/u/barry-thomson)\
**Post date:** [September 7, 2013, 11:28pm UTC](https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863/1 "2013-09-07T23:28:59Z")

</div>

Hi,

Sorry, total nooby question here. I’ve just started trying to learn powershell, and have a simple script that I use to find Mac addresses.

$Name = Read-Host “Enter Machine Name”  
Get-WmiObject win32\_networkadapter -ComputerName $Name |  
where {$\_.physicaladapter -eq $true} |  
Select-Object macaddress,netconnectionid  
PAUSE

I’d like for this script, once finshed, to prompt the user to continue, and then go back to the start. Could someone point me in the right direction?

Many thanks

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [September 7, 2013, 11:48pm UTC](https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863/2 "2013-09-07T23:48:15Z")

</div>

First question has to be what are you trying to achieve?

if this meant to be an interactive tool or are you trying to get the MAC address of a number of machines

I’m going to assume the latter in which case you want something like this:  
`
param ([string]$name)
Get-WmiObject -Class Win32_NetworkAdapter -Filter “PhysicalAdapter = $true” -ComputerName $Name |
Select-Object macaddress,netconnectionid
`

The param block accepts the name of the computer. I moved the filter into the Get-WmiObject -Filter because then the filter happens on the remote machine not your local machine  
Save the script as get-macaddress  
You can use it like this  
.\get-macaddress.ps1 -name server02  
.\get-macaddress.ps1 -name server03  
.\get-macaddress.ps1 -name exch10

Better still make the script a function that accepts pipeline input  
`
function get-macaddress {
[CmdletBinding()]
param (
[parameter(ValueFromPipeline=$true)]
[string]$Computername
)
PROCESS {
Get-WmiObject -Class Win32_NetworkAdapter -Filter “PhysicalAdapter = $true” -ComputerName $Computername |
Select-Object PSComputerName, macaddress,netconnectionid
}
}`

`
`

Load the function like this:  
. .\get-macaddress.ps1

You can then use it like this:  
get-macaddress -Computername server02  
get-macaddress -Computername server03  
get-macaddress -Computername exch10  
“server02”, “server03”, “exch10” | get-macaddress

I would strongly urge you to buy and read Powershell in a Month of Lunches ([Learn Windows PowerShell in a Month of Lunches, Second Edition](http://www.manning.com/jones3)) which is the best introduction to PowerShell

---

<div class="post-metadata">

**Author:** ![barry-thomson](https://avatars.discourse-cdn.com/v4/letter/b/ecb155/32.png) [@barry-thomson](https://forums.powershell.org/u/barry-thomson)\
**Post date:** [September 8, 2013, 12:00am UTC](https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863/3 "2013-09-08T00:00:53Z")

</div>

This is fantastic, thank you.

I’m reading Windows Powershell 3.0 First Steps, at the moment, and will probably read your suggestion too.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:57pm UTC](https://forums.powershell.org/t/how-do-you-get-a-script-to-start-again-from-the-top/1863/4 "2024-05-16T20:57:04Z")

</div>

Closed on May 16, 2024, 8:57pm UTC


