by turbomcp at 2012-09-09 13:41:00
Hiby DonJ at 2012-09-09 13:46:29
i am a newbie in powershell and although i think i understand the basics i am trying to do something very simple(just as a test of doing something else) and its not working:)
im sure any powersheller can see the problem in one sec
here is my code:$items=Get-WmiObject -List |? {$.name -like "tcpip"}
foreach($i in $items)
{
if ($i.name -like "tcpv6")
(Write-Host -ForegroundColor blue " is the item with tcpv6")
if ($i.name -like "tcpv4")
(Write-Host -ForegroundColor green " is the item with tcpv4")
}
basicly i just want to get some data from somewhere
and then have powershell go through it and do certain actions based on what it finds…
thanks in advance for any help
You’ve written your If constructs wrong.by turbomcp at 2012-09-09 13:50:21
if ($i.name -like "tcpv6")
{Write-Host -ForegroundColor blue " is the item with tcpv4"}
if ($i.name -like "tcpv4")
{Write-Host -ForegroundColor green " is the item with tcpv6"}
The conditional code goes in {curly brackets} not (parentheses). Run "help about_if*" in the shell for more details.
Thanks manby turbomcp at 2012-09-09 14:11:22
highly appreciated
works:)
thanks for lightning fast reply
another quick one:)by turbomcp at 2012-09-09 14:39:42
so i changed it to this:$items=Get-WmiObject -List |? {$.name -like "tcpip"}
foreach($i in $items){
if ($i.name -like "*tcpv6")
{Write-Host -ForegroundColor blue "$i is the item with tcpv6"}
if ($i.name -like "*tcpv4")
{Write-Host -ForegroundColor green "$i is the item with tcpv4"}
}
but i noticed output is all in green like this:
\LAP1\root\cimv2:Win32_PerfFormattedData_Tcpip_TCPv4 is the item with tcpv4
\LAP1\root\cimv2:Win32_PerfRawData_Tcpip_TCPv4 is the item with tcpv4
\LAP1\root\cimv2:Win32_PerfFormattedData_Tcpip_TCPv6 is the item with tcpv6
\LAP1\root\cimv2:Win32_PerfRawData_Tcpip_TCPv6 is the item with tcpv6
so even whats suposed to be blue(v6) is green
what am i missing here?
sorry
my mistake
it was fine:)