and then the free disk space calculation is used ,
if ( $diskObject.FreeSpace -lt ($diskObject.Size)*$spaceThreshold ) {
…
or
if ( $diskObject.Free -lt ($diskObject.Free+$diskObject.Used)*$spaceThreshold ) {
…
…
when I run the script from within ISE in the context of an account that is local administrator it works fine, however when I schedule the script to run as a scheduled task in the context of a “service” account that is a non-administrator user then the $diskObject variable contains value 0 i.e not information pertaining to the local disk I am enumerating.
I tried modifying access privileges for the non-administrator on the ROOT of the WMI namespace (wmimgmt.msc) and adding it to both Distributed COM Users and WinRMRemoteWMIUsers_ local group but so far to no avail.
The script performs a backup of the ADCS infrastructure and one of the first checks it does is to make sure there is sufficient amount of available disk space before starting the backup procedure,
and the non-administrator account that I run the script as is a member of BUILTIN\Backup Operators and has only Log on as batch job privileges and it is configured to run with the highest privileges, I am not sure whether maybe some GPO settings might be preventing a proper execution but it would be strange…
I know it works this way and I see this pretty often, but why? If I have a .ps1 file to run, why I don't take the parameter -File instead of -Command? Please don't get me wrong. I'm not complaining - I just would like to understand. Where do you get the idea to do it this way?