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:
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
Getting the owners sometimes needs Admin rights but not always. Here are 4 different outputs :
# Compact view for pasting into email
Get-ChildItem "D:\SASWork" -File -recurse | select Directory, Name, length, <# path, filename,#> lastwritetime, @{Name="Owner";
Expression={ (Get-ACL $_.Fullname).Owner }} | Sort-Object -Descending length | Out-GridView
# Write to standard output for selecting details
Get-ChildItem "D:\SASWork" -File -recurse | select Directory, Name, length, <# path, filename,#> lastwritetime, @{Name="Owner";
Expression={ (Get-ACL $_.Fullname).Owner }} | Sort-Object -Descending length | Format-Table
# Write to csv for DSD parsing with SAS
Get-ChildItem "D:\SASWork" -File -recurse | select Directory, Name, length, <# path, filename,#> lastwritetime, @{Name="Owner";
Expression={ (Get-ACL $_.Fullname).Owner }} | Export-CSV -Path D:\sas\Batch\datafiles\D_SASWork_Files_$(get-date -f "yyyyMMdd").csv -NoTypeInformation
# Pre-req : Install-Module ImportExcel -AllowClobber -Force
# Write to xlsx
Get-ChildItem "D:\SASWork" -File -recurse | select Directory, Name, length, <# path, filename,#> lastwritetime, @{Name="Owner";
Expression={ (Get-ACL $_.Fullname).Owner }} | Export-Excel -Path D:\SAS_Users\AFarrer\xlsx\D_SASWork_Files_$(get-date -f "yyyyMMdd").xlsx
Hi @Acf2
I've written this script for windows to display all existing SAS WORK Directories (_TD*), and SAS Utility directories (SAS_util*), then find their associated process id (PID), if active, with every found directory. This was inspired by the WORKtop freeware utility developed back in the day by the folks from Boemska
:: ----------------------------------------------------------------------- :: Filename: getworkdirpid.bat :: Description: Find all existing SAS WORK Directories (_TD*), and :: SAS Utility directories (SAS_util*), then find their associated :: process id (PID), if active, with every found directory :: ----------------------------------------------------------------------- :: Syntax: :: :: To generate output on the screen, just execute the script :: > getworkdirpid.bat /v f: c: :: :: To store generated output into a text file, here is an example usage :: > getworkdirpid.bat /v f: c: > c:\tmp\getworkdirpid_output.txt :: :: ----------------------------------------------------------------------- @ECHO OFF :: Ensure that I don’t clobber any existing variables after my script exits SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION :: Store the name of the script (without the file extension) SET scrpt=%~n0 :: Store the path of the folder for the script file for later user SET parent=%~dp0 :: Command line parameter check ECHO.%* | FIND "?" >NUL IF NOT ERRORLEVEL 1 GOTO SYNTAX IF "%1" == "/v" SET allArgs=%2 IF NOT defined allArgs GOTO SYNTAX :: Initialize variable SET n=2 SET dirCount=0 :: Skip to the next argument SHIFT :LOOP :: Change directory, and try to find the SAS temporary directories %1 ECHO. ECHO Searching _TD* directories on %1 ... FOR /F %%I IN ('DIR _TD* /s /ad /b') DO ( SET /a dirCount+=1 CALL :unifyLength %%~I, col SET argVec[!dirCount!].fullPath=!col! CALL :getDirPid %%~nI, pid, w SET argVec[!dirCount!].pid=!pid! CALL :getPidInfo !pid!, pidInfo :: echo !pidInfo! SET argVec[!dirCount!].pidInfo=!pidInfo! ) ECHO. ECHO Searching SAS_util* directories on %1 ... FOR /F %%I IN ('DIR SAS_util* /s /ad /b') DO ( SET /a dirCount+=1 CALL :unifyLength %%~I, col SET argVec[!dirCount!].fullPath=!col! CALL :getDirPid %%~nI, pid, u SET argVec[!dirCount!].pid=!pid! CALL :getPidInfo !pid!, pidInfo :: echo !pidInfo! SET argVec[!dirCount!].pidInfo=!pidInfo! ) SET /a n+=1 SHIFT SET param=%1 if defined param (GOTO :LOOP) else (GOTO :REPORT) :SYNTAX ECHO. ECHO Display list of SAS Temporary directories, and their associated PID, if any ECHO Usage: getworkdirpid [/v volume(s)] ECHO Where: /v volume specifies the volume to search for SAS Temporary directories. ECHO Note: When specifying more than one volume, separate them with spaces. ENDLOCAL ECHO ON @EXIT /B 0 :unifyLength SETLOCAL ENABLEEXTENSIONS SET "spaces= " SET "newCol=%1%spaces%" SET newCol=%newCol:~0,77% :: ECHO %newCol% ENDLOCAL&SET %2=%newCol%&GOTO :eof :getDirPid SETLOCAL ENABLEEXTENSIONS SET lclPid=%~nx1 IF "%3" == "w" ( SET lclPid=%lclPid:~3,4% ) else ( SET lclPid=%lclPid:~12,8% SET /A lclPid=0X%lclPid% ) :: echo %lclPid% ENDLOCAL&SET %2=%lclPid%&GOTO :eof :getPidInfo SETLOCAL ENABLEEXTENSIONS tasklist /v /fi "PID eq %1" /nh /fo "CSV" > c:\temp\_tmp.txt ENDLOCAL&SET /p %2=<c:\temp\_tmp.txt&GOTO :eof :REPORT ECHO. ECHO Number of found temporary directories: %dirCount% ECHO ------------------------------------------------------------------------------+-------+------------------------------------------------------ ECHO Directory : PID : Task / Process ECHO ------------------------------------------------------------------------------+-------+------------------------------------------------------ for /L %%i in (1,1,%dirCount%) do ( ECHO !argVec[%%i].fullPath! : !argVec[%%i].pid! : !argVec[%%i].pidInfo! ) ENDLOCAL ECHO ON @EXIT /B 0
The SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment.
SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.
Find more tutorials on the SAS Users YouTube channel.