Link to home
Start Free TrialLog in
Avatar of Zack
ZackFlag 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.
ASKER CERTIFIED SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of Zack

ASKER

Hi Jose,

Thank you very much for the explanation.
Glad to help Zac :) I learned that the hard way :)
EXPERT CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 :)