I'm trying to make a dynamic multiple selection menu via powershell, based on data imported via a CSV file.
After importing objects via CSV, and try to add multiple filters on the SEL
and RESTART
fields and on their values. I see a strange behavior of the counter, to count the number of objects which are conform the different conditions/filters.
It seems that counting 01 returns no display ... suggestion, ideas (I've it also done with one filtering ... same problem)
## MENU
$csvFilePathMENU=CheckFileExcist –FileName $csvFileMENU -FilePath $csvPathMENU
# import the objects ... and put it into a variable
$global:menus = Import-Csv $csvFilePathMENU
$global:nrElemsMENU=$menus.Count
write-output "$($nrElemsMENU)"
I tried two different ways ... to filter
$nrRestarts=$($menus | Where-Object {( $_.RESTART -as [int] -eq 1 )} | Where-Object {( $_.SEL -as [int] -eq 1 )} ).count
write-host "nrRestarts : ", $nrRestarts
$nrRestarts2=$($menus | Where {( $_.RESTART -as [int] -eq 1 ) -and ( $_.SEL -as [int] -eq 1 )}).count
write-host "nrRestarts : ", $nrRestarts2
[I've tried it with several combinations]
left side picture
INPUT CSV 01 : where SEL and RESTART are 1
MENU : MEINBERG
SEL : 1
RESTART : 1
...
MENU : NTP
SEL : 1
RESTART : 1
RESULT 01 :
- nrRestarts : 2
- nrRestarts : 2
right side picture
INPUT CSV 02 : where SEL and RESTART are 1
MENU : NTP
SEL : 1
RESTART : 1
RESULT 02 :
- nrRestarts :
- nrRestarts :
WRONG/NO RESULT ... ??? 01 ??? any body a suggestion?
In the Windows Powershell ISE ... the feedback
PS C:\Users\Administrator> $nrElemsMENU
9
PS C:\Users\Administrator> $menus
MENU : anti-virus : Windows-Defender
info : Windows-Defender has to be uninstalled, before installing an other anti-virus program
function : Windows-Defender
status : -1
SEL : 0
RESTART : 0
FUNC : stopWindowsDefender
PARENT : Anti-virus
MENU : Windows 'ServerStandard'
info : Windows has to be upgraded if working with an EVALUATION prod key
function :
status : -1
SEL : 0
RESTART : 1
FUNC :
PARENT :
MENU : F-SEC
info : F-SEC has to be configured as an isolated machine on the CSI server
function : F-SEC
status : -1
SEL : 0
RESTART : 0
FUNC : startFSec
PARENT :
MENU : NTP
info : disable default Windows NTP service
function :
status : -1
SEL : 1
RESTART : 0
FUNC :
PARENT : NTP
MENU : MEINBERG
info : disable default Windows NTP service
function :
status : -1
SEL : 0
RESTART : 1
FUNC :
PARENT :
MENU : NTP
info : disable default Windows NTP service
function :
status : -1
SEL : 1
RESTART : 1
FUNC :
PARENT :
MENU : openssl
info : disable default Windows NTP service
function :
status : -1
SEL : 0
RESTART : 0
FUNC :
PARENT : OpenSSL
MENU : execute
info :
function :
status : -1
SEL : 0
RESTART : 1
FUNC :
PARENT :
MENU : quite
info :
function :
status : -1
SEL : 0
RESTART : 1
FUNC :
PARENT :