We help IT Professionals succeed at work.

Experimenting with the Openfiles command via powershell

187 Views
Last Modified: 2019-02-07
Hi EE,

I want to write a PowerShell export the contents of the following query:

openfiles /v /query  /fo CSV

Open in new window


So far I have:

$Session = New-PSSession -ComputerName SERVERNAME -ConfigurationName OpenShareFileSearch

$sb = {
    
    openfiles /v /query  /fo CSV | 
        select -skip 8 |
        ConvertFrom-Csv | 
}

Invoke-Command -Session $Session -ScriptBlock $sb |
     Export-Csv C:\temp\FileSearchResults.csv

Open in new window


I am getting the following error message:

[ict00441] Connecting to remote server failed with the following error message : The WinRM client sent a request to an
HTTP server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP serv
er that does not support the WS-Management protocol. For more information, see the about_Remote_Troubleshooting Help to
pic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
   eption
    + FullyQualifiedErrorId : PSSessionOpenFailed
Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument tha
t is not null or empty and then try the command again.
At C:\temp\filename.ps1:10 char:24
+ Invoke-Command -Session <<<<  $Session -ScriptBlock $sb |
    + CategoryInfo          : InvalidData: (:) [Invoke-Command], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand

Any assistance is welcome.

Thank you.
Comment
Watch Question

Top-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT
Top Expert 2014

Commented:
Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
That error makes it pretty clear that the problem is with your New-PsSession command.  I'm not sure why you would have created a new PS configuration, but try it with just the default.
$Session = New-PSSession -ComputerName SERVERNAME

Open in new window

And if you're not running other commands afterward that need to use the same session, then just use the -computername parameter of Invoke-Command (instead of -session) so that the session is torn down immediately after it's used.
ZackGeneral IT Goto Guy

Author

Commented:
Hi Jose,

Thank you very much for the explanation.
Jose Gabriel Ortega CastroTop-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
Glad to help Zac :) I learned that the hard way :)
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Jose Gabriel Ortega CastroTop-Rated Plus Freelancer (Upwork)/EE Solution Guide / CEO / Photographer
CERTIFIED EXPERT
Awarded 2018
Distinguished Expert 2018

Commented:
It's ok if you want the answer bud, I don't mind.
I used to test the code, but I didn't have the time to do so this week. so fine if the author benefits from it :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions