I'm having an issue piping a string element from an object into Get-ChildItem. My code is below:
$RegEx = 'Auto Apply Quota Path:\s+(.*)[\s\S]*?' +
'Source Template:\s+(.*)\s+' +
'Limit:\s+(.*)'
[int]$i = 0
[array]$objArr = @()
(dirquota au l | Out-String) -split '\r\n\r\n' | Where-Object {
$_ -match $RegEx
} | ForEach-Object {
$objArr += New-Object -Type PSObject -Property ([ordered]@{
QuotaPath = $matches[1]
Template = $matches[2]
QuotaLimit = $matches[3]
})
}
$objArr | % {
gci $objArr[$i].QuotaPath
$i++
} | Export-Csv -Path 'E:\outfile.csv'
Now I'm pretty sure the problem is because dot-referencing the string element in the object returns the property of the string, which is Length, and I've verified this with the outfile.csv. I need the string itself and am not having any luck finding out how to get that.
Below is the error message, which oddly contains the string I need, which is the UNC path, and it DOES exist:
gci : Illegal characters in path.
At line:20 char:5
+ gci $objArr[$i].QuotaPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (E:\Dir\Subdir:String) [Get-ChildItem], ArgumentException
+ FullyQualifiedErrorId : ItemExistsArgumentError,Microsoft.PowerShell.Commands.GetChildItemCommand
gci : Cannot find path 'E:\Dir\Subdir' because it does not exist.
At line:20 char:5
+ gci $objArr[$i].QuotaPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (E:\Dir\Subdir:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
The solutions I've seen online say to put the string into a custom object, but they're already in an object, so that doesn't help. I'm sure I'm missing something obvious.
$objArr | % { $objArr[$i].QuotaPath $i++ } | Export-Csv -Path 'E:\outfile.csv'I get a CSV file with this: #TYPE System.String "Length" "21" "21" "21" "21" "17" - Ash Housewares