Variable Path Error

Welcome Forums General PowerShell Q&A Variable Path Error

Viewing 2 reply threads
  • Author
    Posts
    • #230125
      Participant
      Topics: 2
      Replies: 0
      Points: 23
      Rank: Member

      I receive an error on the follow variable. It cannot find the path to where log folder is stored. I have been debugging for a day and issue remains. I appreciate any advice and or help.

      ***********************************************************************************************************************

      Here is Variable: $Logfolder = ‘C:\Util\LogFileServer\’

      PS C:\Users\> $DFSShare = Get-Content -Path $Logfolder
      Get-Content : Could not find a part of the path ‘C:\Util\LogFileServer\’.
      At line:1 char:13
      + $DFSShare = Get-Content -Path $Logfolder
      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo : ObjectNotFound: (C:\Util\LogFileServer\:String) [Get-Content], DirectoryNotFoundException
      + FullyQualifiedErrorId : GetContentReaderDirectoryNotFoundError,Microsoft.PowerShell.Commands.GetContentCommand

      **********************************************************************************************************************

    • #230134
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      You provide a path to a folder where you should provide a path to a file.

    • #230158
      Participant
      Topics: 0
      Replies: 14
      Points: 175
      Helping Hand
      Rank: Participant

      Olaf is correct here.

      The Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file.

      Also you can specify a filter to the Get-Content cmdlet. When using filters to qualify the Path parameter, you need to include a trailing asterisk (*) to indicate the contents of the path:

      
      Get-Content -Path C:\Temp\* -Filter *.log
      
      

       

      Reference: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7

       

       

Viewing 2 reply threads
  • You must be logged in to reply to this topic.