Getting newest file info from remote computer (Invoke or PSSession)

Welcome Forums General PowerShell Q&A Getting newest file info from remote computer (Invoke or PSSession)

Viewing 4 reply threads
  • Author
    Posts
    • #279930
      Participant
      Topics: 6
      Replies: 13
      Points: 100
      Rank: Participant

      A computer that should be creating a log file wasn’t and hadn’t been for a month or so. I’d like to be able to run something like the below within Invoke-Command so I don’t need to log in to find out if it’s running but I don’t seem to be able to no matter how I seem to modify it. Would PSSession work better for this?

       

       

      • This topic was modified 1 month ago by ALombardi01. Reason: Crayon formatting jacked up
    • #279942
      Participant
      Topics: 10
      Replies: 201
      Points: 987
      Helping Hand
      Rank: Major Contributor

      what happens if you change this:

      $Dir = ‘c:\logs’

      To this:

      $dir = “\\$computer\c$\logs”

      You would of course need to define $computer as the remote computer. I am unable to test, but my thought is using this method would only require admin on the remote system and you dont have to mess with remote powershell.

    • #279945
      Participant
      Topics: 6
      Replies: 13
      Points: 100
      Rank: Participant

      what happens if you change this:

      $Dir = ‘c:\logs’

      To this:

      $dir = “\\$computer\c$\logs”

      You would of course need to define $computer as the remote computer. I am unable to test, but my thought is using this method would only require admin on the remote system and you dont have to mess with remote powershell.

      Doesn’t work. I tried it whether or not the directory is shared or not, and all I get is Access Denied. I’m using a Domain Admin account too to test.

    • #279948
      Participant
      Topics: 10
      Replies: 201
      Points: 987
      Helping Hand
      Rank: Major Contributor

      C$ is always shared by default, but not accessible by default. There are changes you can make to get this to work (GPO), but that of course increases the security risk. Not sure which will be easier, getting PSRemoting configured or access to C$.

      • #279954
        Participant
        Topics: 6
        Replies: 13
        Points: 100
        Rank: Participant

        C$ is always shared by default, but not accessible by default. There are changes you can make to get this to work (GPO), but that of course increases the security risk. Not sure which will be easier, getting PSRemoting configured or access to C$.

        Yeah. I wouldn’t open things up. I may need to just move the files from C: as I believe this specific server has a D: share for something else. May just need it to end up there and I may be able to do it that way instead.

    • #279957
      Participant
      Topics: 10
      Replies: 201
      Points: 987
      Helping Hand
      Rank: Major Contributor

      You mention “server” … typically, PSRemoting is enabled on Servers. Have you run any tests to check the server as in Test-WSMan?

      If that looks good, change your script to this (again, I am unable to test)

      $Latest = Invoke-Command -ComputerName $Computer -ScriptBlock {Get-ChildItem -Path $Using:dir | Sort-Object CreationTime -Descending | Select-Object -First 1}

      • #279963
        Participant
        Topics: 6
        Replies: 13
        Points: 100
        Rank: Participant

        You mention “server” … typically, PSRemoting is enabled on Servers. Have you run any tests to check the server as in Test-WSMan?

        If that looks good, change your script to this (again, I am unable to test)

        $Latest = Invoke-Command -ComputerName $Computer -ScriptBlock {Get-ChildItem -Path $Using:dir | Sort-Object CreationTime -Descending | Select-Object -First 1}

        This is basically working as I want. Whatever I had my Invoke-command set up as originally wasn’t working, so I posted here, thinking it wasn’t allowed to get the information.

        You solved my answer. Thanks.

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