Invalid Get-ChildItem operation in PowerShell

The internal SQL database contains "managed folders" in the form of UNC paths. Using SQL queries in PowerShell, I have a loop that will work through these folders and run a GCI operation against them to determine how much disk space they are using.

$managedFolder = "\\server\share\folder\subfolder"

In the name of the question is $managedFolderannounced above. Next command:

$diskTrendsInitialUsage = "{0:N2}" -f ((Get-ChildItem $managedFolder -Recurse -Force | Measure-Object -Property Length -Sum).Sum / 1GB)

Now, if I run this command manually in the PS console, that's fine, it discards the data. But as soon as it is packed into a script, it crashes with the error below. The folder is accessible from the server, since it works fine from the local console of the PS console.

ERROR: Get-ChildItem : Invalid Path: '\\server\share\folder\subfolder'.
AddManagedFolder.psf (17): ERROR: At Line: 17 char: 42
ERROR: +         $diskTrendsInitialUsage = "{0:N2}" -f ((Get-ChildItem $managedFolder -Recurse  ...
ERROR: +                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : NotSpecified: (:) [Get-ChildItem], ArgumentException
ERROR:     + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetChildItemCommand
ERROR:

I'm at a dead end.

+4
source share
2 answers

, , , PowerShell . , . , , PowerShell :

$managedFolder = "filesystem::\\server\share\folder\subfolder"
+6

, SQL PS GCI, SQL: , GCI.

GCI cd c:\, , GCI .

+2

Source: https://habr.com/ru/post/1569565/


All Articles