question

Konstantin-8044 avatar image
0 Votes"
Konstantin-8044 asked AndreasBaumgarten commented

Get-ChildItem -Path not working

Hello to All.

I have very simple code

 $ShowDirectory =  "C:\FTP" 
    
 This code working 
    
 Invoke-Command  -ComputerName  $serverName -Credential $cred  {Get-ChildItem -Path "C:\FTP" | select  FullName, LastAccessTime  }
    
 and this is not
    
 Invoke-Command  -ComputerName  $serverName -Credential $cred    {Get-ChildItem  -Path $ShowDirectory | select  FullName, LastAccessTime  }  


it's not accepted path to the directory as a variable.


Thank you for help.

Konstantin


windows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Konstantin-8044 ,

Did the answer work for you? Are there any additional questions to this topic?

If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A

----------
Regards
Andreas Baumgarten

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered AndreasBaumgarten edited

Hi @Konstantin-8044 ,

You have to pass the variable to the script block.

Please try this:

  $ShowDirectory =  "C:\FTP" 
  Invoke-Command -ComputerName  $serverName -Credential $cred -ScriptBlock {Get-ChildItem -Path $using:ShowDirectory | Select-Object FullName, LastAccessTime}  


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Konstantin-8044 avatar image
0 Votes"
Konstantin-8044 answered AndreasBaumgarten commented

Thank you AndreasBaumgarten!!!!!

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Konstantin-8044 ,

you are welcome.

If you found the answer helpful, it would be great if you please mark it "Accept as answer". This will help others to find answers in Q&A


Regards
Andreas Baumgarten

0 Votes 0 ·