Thank you AndreasBaumgarten!!!!!
Get-ChildItem -Path not working
Konstantin
1
Reputation point
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
2 answers
Sort by: Newest
-
-
Andreas Baumgarten 97,076 Reputation points MVP
2021-04-02T18:12:10.843+00:00 Hi @Konstantin ,
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