Avatar of Zack
Zack
Flag for Australia asked on

Experimenting with the Openfiles command via powershell

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.
PowershellMicrosoft Server OSWindows OS

Avatar of undefined
Last Comment
Jose Gabriel Ortega Castro

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jose Gabriel Ortega Castro

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
footech

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.
Zack

ASKER
Hi Jose,

Thank you very much for the explanation.
Jose Gabriel Ortega Castro

Glad to help Zac :) I learned that the hard way :)
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
EXPERT CERTIFIED SOLUTION
footech

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Jose Gabriel Ortega Castro

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 :)