I have to create a script which performs some operations in a given folder, but it must include a prior check if there is enough space left before starting the operations. The folder name is an UNC path, e.g. \\example-server\share1\folder\subfolder\. How can I get the amount of free space in the folder?
Things that I tried so far:
I read that I can use
gwmi,Get-CimInstance,Get-VolumeandGet-PSDriveto get information about a volume, but I don't know how to determine the volume where the folder is stored.I tried using this interesting-looking function,
GetDiskFreeSpaceExin my script but sadly it returned with Success=false and an empty value for "Free".