Hi,
I’ve been at this for a really long time and I’m at my wits end. My script is below. I’m trying to figure out why I’m not getting any objects returned from line 66 when I specify multiple filters in the -include parameter. The script works as expected if I only provide one item in the include filter. If I run the get-childitem cmdlet via my output from line 64 I get the expected number of objects back. Can someone please let me know why the behavior differs when I use the cmdlet in my script versus run get-childitem cmdlet outside my script?
Function Copy-WebLogs
{
param (
[validateSet("wsvcctt","unittest")]
[string]$servertype,
[string]$logName,
[validateSet("Tomcat","IIS","AppLogs","all")]
[string]$logType,
[string]$target
)
Begin
{
$UNIT_TEST = @{servers=”BGTMNWL-G4BZZL1.PEROOT.com”;
LogTypes=”Tomcat”;
Tomcat=”c$\testScripts”;
}
switch ($servertype)
{
‘wsvcctt’ {
$hash = $WEB_SERVICE_CTT
}
‘unittest’ {
$hash = $UNIT_TEST
}
}
}
Process {
$webs= $hash.servers
switch ($logType) {
‘Tomcat’ {
$logDirectory = $hash.Tomcat
}
‘IIS’ {
$logDirectory = $hash.IIS
}
‘AppLogs’ {
$logDirectory = $hash.AppLogs
}
}
<#Check to see if the $target path exists, if not create it. #>
If (!(test-path -Path $target)) {
New-Item -Path $target -ItemType Directory
}
foreach($web in $webs)
{
If (!(test-path -Path $target\$web))
{
New-Item -Path $target\$web -ItemType Directory -ErrorAction Stop
}
#below is line 68
“Get-ChildItem -path \\$web\$logDirectory\* -Include $logName”
#Below is line 70
Get-ChildItem -path \\$web\$logDirectory\* -Include $logName | ForEach-Object {“Found stuff”}
}
}
}