Author Posts

May 29, 2015 at 10:23 am

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}

May 29, 2015 at 10:36 am

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}

May 29, 2015 at 12:00 pm

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

May 29, 2015 at 12:54 pm

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)

June 1, 2015 at 8:15 am

Thanks ##Nick that seemed to do the trick!

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

June 1, 2015 at 3:08 pm

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.