Pull Back Top 10 Biggest Files On a Device

Welcome Forums General PowerShell Q&A Pull Back Top 10 Biggest Files On a Device

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
3 years, 7 months ago.

  • Author
    Posts
  • #25799

    Participant
    Points: 0
    Rank: Member

    I am able to get this to work on the machine I am working on but not when I try to do it remotely.
    I get an error message; "Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported."

    Here is the code:

    {invoke-command (get-childitem | sort-object Length -descending | Select -First 10 | ft @{label="TotalSize(MB)";EXPRESSION={[Math]::Truncate($_.Length/1mb)};width=14}, FullName) -comp Workstation}
  • #25801

    Participant
    Points: 438
    Helping Hand
    Rank: Contributor

    You are not specifying a path for Get-ChildItem. In a local prompt, it would use the current location of the prompt. Try specifying a path and see if that corrects the issue.

    {invoke-command (get-childitem -Path C:\* | sort-object Length -descending | Select -First 10 | ft @{label="TotalSize(MB)";EXPRESSION={[Math]::Truncate($_.Length/1mb)};width=14}, FullName) -comp Workstation}
    
    • #25805

      Participant
      Points: 0
      Rank: Member

      That yielded the same result. "Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'FilePath'. Specified method is not supported."

  • #25809

    Participant
    Points: 1
    Rank: Member

    Jamie,

    I believe the issue is related to your use of parenthesis versus curly braces as your trying to execute a script block. The following command worked great on my machine.

    Invoke-Command -ComputerName MBSQLCLX001 {Get-ChildItem -path '\\mbsqlclx001\C$\_test\Microsoft SQL 2012 - Enterprise - SP2\x64\Setup' | Sort-Object Length -Descending | Select -First 10 | Format-Table @{label="TotalSize(MB)";EXPRESSION={[Math]::Truncate($_.Length/1mb)};width=14}, FullName}

    A couple notes:
    1. I had to find a folder where the file sizes were > 1MB to get anything other than 0.
    2. If your in the ISE using -path C:\*, you'll get the local machine, not the target (guess what I did to figure that out lol)

    • #25849

      Participant
      Points: 0
      Rank: Member

      Thanks ##Nick that seemed to do the trick!

      What did you do to figure it out about the path?

  • #25857

    Participant
    Points: 1
    Rank: Member

    I had simply used the C:\* and found that the folders appearing were the ones local to my pc and not the target of my invoke command.
    Somewhat surprising as your in an invoke command statement yet it still uses the local path. I've learned to always use the UNC path.

The topic ‘Pull Back Top 10 Biggest Files On a Device’ is closed to new replies.