Reputation: 1175
List all filenames that match a pattern but can't seem to get it to list only the files I need I am eventually going to replace the filter with user input
$src = $env:ININ_TRACE_ROOT
$cmp = $env:COMPUTERNAME
$dst = $env:USERPROFILE + "\Desktop\" + $cmp
$lDate = Read-Host "Which Date?"
$s2 = $src + "\$ldate\"
$filter = "ip"
Get-ChildItem -Path $s2 | Where-Object { $_.Name -match $filter } | Select Name
Tried the above problem is it returns
accserver.zip
acdserver.zip
adminserver.zip
adminserver_1.zip
caasbillingserver.zip
caasproxyserver.zip
CallLog.zip
clientservices.zip
ClientStatsWkgQDataLog.zip
compressormanager.zip
datamanager.zip
dsserver.zip
fbmc.zip
hostserver.zip
httppluginhost.zip
i3runcrreport.zip
i3runcrreport_1.zip
i3runcrreport_2.zip
i3runcrreport_3.zip
imapconnector.zip
ininfaxserver.zip
interactionclient.zip
interactionrecoveryu.zip
ip.ininlog_journal
ip.zip
ipdbserver.ininlog_journal
ipdbserver.zip
ipserver.ininlog_journal
ipserver.zip
ip_1.zip
ip_10.zip
ip_11.zip
ip_12.zip
ip_13.zip
ip_14.zip
ip_2.zip
ip_3.zip
ip_4.zip
ip_5.zip
ip_6.zip
ip_7.zip
ip_8.zip
ip_9.zip
iwpserver.zip
LineGroupStatsDataLog.zip
mail account monitor.zip
mrcpsubsystem.zip
notifier.zip
notifierserver.zip
notifier_1.zip
notifier_2.zip
notifier_3.zip
optimizer server.zip
OutOfProcCustomDLL.zip
postofficeserver.zip
processautomationserver.zip
promptserver.zip
provisionserver.zip
QueuePeriodAgentStatsDataLog.zip
QueuePeriodWorkgroupStatsDataLog.zip
queuestatprovider.zip
recorder server.zip
RecoSubsystem.zip
remocoserver.zip
rstrapmonitor.zip
sessionmanager.zip
SIPEngine-mrcp.ininlog_journal
SIPEngine-mrcp.zip
SIPEngine.ininlog_journal
SIPEngine.zip
smsserver.zip
smtpconnector.zip
SNMPAgent.zip
statalertserver.zip
statserveragent.zip
statserveragent_1.zip
statserveragent_2.zip
statserverworkgroup.zip
statserverworkgroup_1.zip
statserverworkgroup_2.zip
surveyservice.zip
switchover.zip
switchoverfilemonitor.zip
tracker server.zip
tracker server_1.zip
transactionserver.zip
transactionserver_1.zip
transactionserver_2.zip
transactionserver_3.zip
transactionserver_4.zip
tsserver.zip
tsserver_1.zip
tsserver_2.zip
tsserver_3.zip
voicexml host server.zip
Problem is I need it to only return
ip.zip
ip_1.zip
ip_10.zip
ip_11.zip
ip_12.zip
ip_13.zip
ip_14.zip
ip_2.zip
ip_3.zip
ip_4.zip
ip_5.zip
ip_6.zip
ip_7.zip
ip_8.zip
ip_9.zip
Any ideas on how to achieve this
Updated using this now returns the list but is there a better way to do it?
$filter = "^ip[^server][^db][^ininlog_journal]"
Also this works but missing the non ip.zip
$filter = "^ip_[0-9]"
Upvotes: 0
Views: 148
Reputation: 24555
Since -match
uses a regular expression, you should be able to write something like this:
get-childitem $s2 | where-object { $_.Name -match '^ip' }
(i.e., match when the Name property starts with ip
).
See the about_Regular_Expressions
help topic for more information.
Upvotes: 3