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
}
Friday, June 1, 2012
Subtraction worksheet
A somewhat irrelevant post. I had to quickly produce a sheet of 100 random subtraction drills for my 2nd grader. I can think of 10 or 20 ways to make this more compact and useful.:
0..19 | % {write "$(get-random -max 21 -min 14) - $(get-random -max 6 -min 0)"} | out-file mixed100.txt
0..19 | % {write "$(get-random -max 16 -min 9) - $(get-random -max 6 -min 0) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 11 -min 6) - $(get-random -max 6 -min 0) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 21 -min 14) - $(get-random -max 11 -min 6) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 15 -min 9) - $(get-random -max 9 -min 3) = "} | out-file -append mixed100.txt
PS C:\Windows\system32> more mixed100.txt
19 - 3 =
16 - 5 =
19 - 1 =
18 - 5 =
18 - 2 =
17 - 1 =
16 - 0 =
14 - 0 =
...
0..19 | % {write "$(get-random -max 21 -min 14) - $(get-random -max 6 -min 0)"} | out-file mixed100.txt
0..19 | % {write "$(get-random -max 16 -min 9) - $(get-random -max 6 -min 0) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 11 -min 6) - $(get-random -max 6 -min 0) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 21 -min 14) - $(get-random -max 11 -min 6) = "} | out-file -append mixed100.txt
0..19 | % {write "$(get-random -max 15 -min 9) - $(get-random -max 9 -min 3) = "} | out-file -append mixed100.txt
PS C:\Windows\system32> more mixed100.txt
19 - 3 =
16 - 5 =
19 - 1 =
18 - 5 =
18 - 2 =
17 - 1 =
16 - 0 =
14 - 0 =
...
Subscribe to:
Posts (Atom)