Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Get-Content question

$
0
0

I am trying to resolve files that a specific number of entries in order to move them elsewhere or to call a function. If I split get-childitem and get-content up, I can accomplish my task. I would like to know where my syntax or logic error comes in while attempting to test with both cmdlets being used. I've tried foreach, foreach-object, using a switch, and nested if statements to accomplish my task. I am most likely missing one of the many idiosyncrasies of powershell and would like a PS Vet to clear this up for me. Thanks!

Here is some of the code I'm attempting to use.

$logFiles = Get-ChildItem "C:\MobilePC\Logs" | where{!$_.PSIsContainer} |
Get-Content $_.
foreach($log in $logFiles)
    {
    if ($log.count -eq 3)
        {
        Write-Output "This seems to be working"
        }
    }

Says path is null.

------------------------------------------------------------------------------
$logFiles = Get-ChildItem "C:\MobilePC\Logs" | where{!$_.PSIsContainer}
ForEach ($log in $logFiles)
    {
    switch ((Get-Content $log).count)
        {
        {$_ -eq 3}{Write-Output $log.Name, "Alert 3 days"; break}
        {$_ -eq 6}{Write-Output $log.Name, "Alert 6 days"; break}
        {$_ -eq 9}{Write-Output $log.Name, "Alert 9 days"; break}
        deafult {Write-Output "This is the default case"}
        }
    }

The switch is searching for the log files in my home directory instead of the C:\MobilePC\Logs directory.

I have rearranged this test many different ways and get similar but different errors.


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>