Historic Blog. No longer active. A script repository that stopped at Powershell 4.0 is at www.rmfdevelopment.com/PowerShell_Scripts . My historic blog (no longer active) on Network Security ( http://thinking-about-network-security.blogspot.com ) is also Powershell heavy. AS of 2/27/2014 all Scripts are PS 4.0.
Friday, June 29, 2012
Switch Array Automation
I am working with processing IP Address arrays for some automation I am doing with procmon exported results in Powershell.
#arrays
[array[]]$IParray="RMFHOPE","239.255.255.250"
[array[]]$IPAddress = "239.255.255.250"
# works as expected
$IPAddress = "239.255.255.250"
switch ($IPAddress){
RMFHOPE {write "0"}
239.255.255.250 {write "1"}
}
# now working; required string conversion
[array[]]$IParray="RMFHOPE","239.255.255.250"
[array[]]$IPAddress = "239.255.255.250"
$IPC= ($IParray.count)- 1
0..$IPC | % -process {
[string]$IP=$IPArray[$_] #needed string conversion here
switch ($IPAddress){
($IP) {write $IPAddress}
}
}
# prints IP Address
foreach ($i in (0..$IPC)) {switch ($IPAddress) {$IPArray[$i] {write $IPAddress}}}
# prints array item place
foreach ($i in (0..$IPC)) {switch ($IPAddress) {$IPArray[$i] {$i}}}
#stores and prints all $IPArray then all $IPArray item place
#arrays
[array[]]$IParray="RMFHOPE","239.255.255.250"
[array[]]$IPAddress = "239.255.255.250"
$IPC= ($IParray.count) - 1
#All $IPArray
$IPArray | % -process {
[array[]]$IPAddress = $_
$a=foreach ($i in (0..$IPC)) {switch ($IPAddress) {$IPArray[$i] {$IPArray[$i]}}}
$a
}
#All $IPArray item place
$IPArray | % -process {
[array[]]$IPAddress = $_
$a=foreach ($i in (0..$IPC)) {switch ($IPAddress) {$IPArray[$i] {$i}}}
$a
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment