I am trying to display a progress bar with the write-progress cmdlet for a change in ip address settings.
I have the interface
$iface = Get-WMiObject Win32_NetworkAdapterConfiguration | Where{$_.IPEnabled -eq “TRUE”}
and I have the changes
$iface.enablestatic($ip,$subnet)
$iface.setdnsserversearchorder($dns)
$iface.setgateways($gate)
$iface.SetDynamicDNSRegistration(“FALSE”)
How can I use write-progress to display the time taken to change the ip and subnet mask?
I’m not sure Write-Progress is the right tool here. These steps should complete very quickly, and the progress indicator would just flash by. For example:
(On a side note, keep in mind that $iface might be an array, if you have multiple IP-enabled adapters on your system.)
Are you looking for something more like verbose output of the exact amount of time each operation took? For that, the code might look something like this:
$elapsed = Measure-Command { $iface.enablestatic($ip,$subnet) }
Write-Verbose ('Time to assign IP / Subnet Mask: {0:F2}ms' -f $elapsed.TotalMilliseconds)
# and so on
[quote=14281]I’m not sure Write-Progress is the right tool here. These steps should complete very quickly, and the progress indicator would just flash by. For example:
(On a side note, keep in mind that $iface might be an array, if you have multiple IP-enabled adapters on your system.)
Are you looking for something more like verbose output of the exact amount of time each operation took? For that, the code might look something like this:
$elapsed = Measure-Command { $iface.enablestatic($ip,$subnet) }
Write-Verbose ('Time to assign IP / Subnet Mask: {0:F2}ms' -f $elapsed.TotalMilliseconds)
# and so on
[/quote]
Thank you so much for the help! I believe I understand what you mean when you talk about multiple adapters being in use. I tried the write-progress lines that you showed and when run in ISE it asks me to supply values for the parameter “Status”.
Write-Progress : Cannot bind argument to parameter ‘Status’ because it is an empty string.
At C:\TCPSettings.ps1:53 char:15
Ah, looks like -Status was a mandatory parameter in PowerShell 2.0; I assume that’s what you’re running? You can add it to each of the calls to Write-Progress, if so:
[quote=14284]Ah, looks like -Status was a mandatory parameter in PowerShell 2.0; I assume that’s what you’re running? You can add it to each of the calls to Write-Progress, if so:
I am still getting the same prompt for status plus a new error. I did not think anything was wrong with the way I got the interface but this is an error meaning that the value cannot be used for write-progress?
Write-Progress : Cannot bind parameter ‘Id’. Cannot convert the “System.Management.ManagementBaseObject” value of type “System.Management.ManagementBaseObject#__PARAMETERS” to type
“System.Int32”.
At C:\Users\brant\Documents\TCPSettings.ps1:47 char:19
Write-Progress <<<< -Activity 'Configuring Network Adapter' -Status 'Processing' -CurrentOperation 'Assigning IP and Subnet' -PercentComplete 0 $iface.enablestatic($ip,$subnet
Write-Progress : Cannot bind parameter ‘Id’. Cannot convert the “System.Management.ManagementBaseObject” value of type “System.Management.ManagementBaseObject#__PARAMETERS” to type
“System.Int32”.
At C:\Users\brant\Documents\TCPSettings.ps1:49 char:15
Write-Progress : Cannot bind parameter ‘Id’. Cannot convert the “System.Management.ManagementBaseObject” value of type “System.Management.ManagementBaseObject#__PARAMETERS” to type
“System.Int32”.
At C:\Users\brant\Documents\TCPSettings.ps1:51 char:15
Write-Progress : Cannot bind parameter ‘Id’. Cannot convert the “System.Management.ManagementBaseObject” value of type “System.Management.ManagementBaseObject#__PARAMETERS” to type
“System.Int32”.
At C:\Users\brant\Documents\TCPSettings.ps1:53 char:15
It looks like you’ve put multiple statements on the same line, somehow. There should be a line break between “-PercentComplete xx” and $iface.Whatever()