BookmarkSubscribeRSS Feed
Acf2
Calcite | Level 5

I need to provide some SAS admin tools to non-SAS admins for a very basic Windows2019 server with about 25 occasional EG users. Due to shared disk, Environment Manager is not reliable and does not integrate with the IT team. cleanwork.exe is scheduled but sometimes a lot of users need a lot of space at the same time.

 

This powershell script can be supported by IT operations and the output is sufficient for basic capacity planning but it needs some tweaking. Hopefully, I am not missing something obvious:

 

# Write owner and aggregate SASwork usage to csv
# D:\sas\Batch\scripts\SASWorkDirUse2csv.ps1
# Nearly there but array($owner) values are weird
<#
tree /A D:\SASWork
Folder PATH listing for volume Data
Volume serial number is EE9D-7C3D
D:\SASWORK
+---SAS_util0001000008C0_WIN2019SRV
+---SAS_util000100007504_WIN2019SRV
+---SAS_util000100008B28_WIN2019SRV
+---SAS_util0001000095B4_WIN2019SRV
+---_TD2240_WIN2019SRV_
|   +---EC_4qh9k9re
|   \---Prc2
+---_TD29956_WIN2019SRV_
|   +---EC_jh9gtz1t
|   \---Prc2
+---_TD35624_WIN2019SRV_
|   +---EC_1gt8bc1d
|   \---Prc2
+---_TD38324_WIN2019SRV_
|   +---EC_nb5qr46m
|   \---Prc2
\---_TD4000_WIN2019SRV_
#>

$folder = 'D:\SASWork'

$DirUseArray = @()
 
# Get a list of first level sub-folders
$firstLevel = Get-ChildItem $folder -directory
 
$firstLevel | foreach {
   Echo "Reading $_"
   # Read the size of this folder and all its sub folders.
   $size = (Get-ChildItem $folder\$_\* -recurse) | measure-object -property length -sum | Select-Object -expand sum
   # Convert from Bytes to GB and round to 2 decimal places
   $size =  [math]::Round($(0 + $size /1GB),2)
   $owner = (Get-ChildItem $folder\$_ -directory) | select @{Name="Owner";Expression={ (Get-ACL $_.Fullname).Owner }}
   Echo $owner $size
 
   # Add to an array
   $DirUseArray += New-Object PsObject -property @{
      'Owner' = $owner
      'Folder' = $_
      'Size (GB)' = $size
   }
}
# $DirUseArray | Export-Csv -path D:\sas\Batch\datafiles\SASWorkDirUse.csv -NoTypeInformation
$DirUseArray

#<
Size (GB) Folder                            Owner                                            
--------- ------                            -----                                            
        0 SAS_util0001000008C0_WIN2019SRV                                                  
        0 SAS_util000100007504_WIN2019SRV                                                  
        0 SAS_util000100008B28_WIN2019SRV                                                  
        0 SAS_util0001000095B4_WIN2019SRV                                                  
     4.59 _TD2240_WIN2019SRV_             {@{Owner=SASUSER1}, @{Owner=SASUSER1}}    
     1.14 _TD29956_WIN2019SRV_            {@{Owner=SASUSER1}, @{Owner=SASUSER1}}    
    19.76 _TD35624_WIN2019SRV_            {@{Owner=SASUSER2}, @{Owner=SASUSER2}}
    19.76 _TD38324_WIN2019SRV_            {@{Owner=SASUSER2}, @{Owner=SASUSER2}}
        0 _TD4000_WIN2019SRV_                                                              
#>
 
 

I am testing using an account that is a member of the Administrators group but I have noticed that get-acl can be erratic if not run as Administrator. Still testing that aspect. The original script came from DirUse Directory size - PowerShell - SS64.com

An excellent resource for powershell amateurs

 

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

CLI in SAS Viya

Learn how to install the SAS Viya CLI and a few commands you may find useful in this video by SAS’ Darrell Barton.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 0 replies
  • 719 views
  • 0 likes
  • 1 in conversation