Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question abt get-childitem

Status
Not open for further replies.

SEPORY

Technical User
Nov 11, 2008
1
SE
Why can´t I substitute a string variable in get-childitem expression

I try to write
$strExclude ="*?.resx,web.config"
Get-ChildItem *.* -exclude $strExclude

If I run that script the Get-ChildItem don´t seem to recognize the exclusion part.

But if I write Get-ChildItem *.* -exclude *?.resx,web.config it works nice

Get-ChildItem don´t seem to evaluate my string substitution correctly

any idea,
 
Have you patched your box recently? Just tested exactly that PS on a rollup 4 box and all works fine.
 
Hmm, in PS v1 on my XP SP 3 box get-childitem does not recognize the string. Interestingly, when I look at
Code:
help get-childitem -detailed
there's a sentence on the -exclude parameter which reads "This parameter does not work properly in this cmdlet"...
 
OK, I'll see your "This parameter does not work properly in this cmdlet" and raise you...

I'm checking this on Windows 2003 x64 SP2 with Exchange 2007 x64 SP1 roll up 4....

[PS] C:\>get-childitem *.*


Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/07/2007 21:15 0 AUTOEXEC.BAT
-a--- 07/11/2008 12:33 1155735552 Backup.bkf
-a--- 04/07/2007 21:15 0 CONFIG.SYS
----- 16/02/2007 23:39 135680 msizap.exe


[PS] C:\>$strExclude = "*.bkf"
[PS] C:\>get-childitem *.* -exclude $strexclude


Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/07/2007 21:15 0 AUTOEXEC.BAT
-a--- 04/07/2007 21:15 0 CONFIG.SYS
----- 16/02/2007 23:39 135680 msizap.exe


[PS] C:\>

So it works for a single exclusion.


[PS] C:\>$strexclude = "*.bkf;*.sys"
[PS] C:\>get-childitem *.* -exclude $strexclude


Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/07/2007 21:15 0 AUTOEXEC.BAT
-a--- 07/11/2008 12:33 1155735552 Backup.bkf
-a--- 04/07/2007 21:15 0 CONFIG.SYS
----- 16/02/2007 23:39 135680 msizap.exe


[PS] C:\>$strexclude = "*.bkf *.sys"
[PS] C:\>get-childitem *.* -exclude $strexclude


Directory: Microsoft.PowerShell.Core\FileSystem::C:\


Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 04/07/2007 21:15 0 AUTOEXEC.BAT
-a--- 07/11/2008 12:33 1155735552 Backup.bkf
-a--- 04/07/2007 21:15 0 CONFIG.SYS
----- 16/02/2007 23:39 135680 msizap.exe


[PS] C:\>

But not when you try more than one exclusion whether that is a comma, a semi colon or a space.

i.e. I agree with you that your PS doesn't work though your theory is entirely sound, I just don't know whether it is fixable. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top