Pull Back Top 10 Biggest Files On a Device

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of ##Nick ##Nick 2 years, 1 month ago.

  • Author
    Posts
  • #25799
    Profile photo of Jamie Davenport
    Jamie Davenport
    Participant

    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
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    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
      Profile photo of Jamie Davenport
      Jamie Davenport
      Participant

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

  • #25809
    Profile photo of ##Nick
    ##Nick
    Participant

    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
      Profile photo of Jamie Davenport
      Jamie Davenport
      Participant

      Thanks ##Nick that seemed to do the trick!

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

  • #25857
    Profile photo of ##Nick
    ##Nick
    Participant

    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.

You must be logged in to reply to this topic.