Disk Monitoring Questions

Hi!
I´m new to UiPath :slight_smile:
I´m trying to run a PoweShell script using Read text → Invoke Power Shell and running the script:
$diskInfo = Get-WmiObject -Class Win32_LogicalDisk | Select-Object DeviceID, FreeSpace, Size
$diskInfo | Format-Table -AutoSize

It wont run, I´m trying to make it check on my disk space and then act according to predefined rules, such as if the available space is <5MB it will open PowerShell and move “new folder” under “removed-folder” or report that the Drive has enough space.

$diskInfo = Get-WmiObject -Class Win32_LogicalDisk | Select-Object DeviceID, FreeSpace, Size

foreach ($disk in $diskInfo) {
$freeSpaceMB = [math]::Round($disk.FreeSpace / 1MB, 2)

if ($freeSpaceMB -lt 5) {
    # Move "new folder" under "removed-folder"
    Move-Item -Path "C:\path\to\removed-folder\new folder" -Destination "C:\path\to\new-folder"

    # You can also report that the drive has enough space here
    Write-Host "Drive $($disk.DeviceID) is running low on space, 'new folder' has been moved."
} else {
    # Report that the drive has enough space
    Write-Host "Drive $($disk.DeviceID) has sufficient space ($freeSpaceMB MB)."
}

}

Note : Replace “C:\path\to\removed-folder\new folder” and “C:\path\to\new-folder” with the actual paths to your folders. This script will check the available space on all logical disks and move the folder if space is less than 5MB, or report that there’s enough space.
@Anna_Kristin_Hjaltalin_Ag

Thank you for your answer. I´m still having issues with the RPA to open the text document and then opening powershell to run the script, any ideas what I´m doing wrong?

Fine
May I know what error u r getting
@Anna_Kristin_Hjaltalin_Ag

Yes sorry, here it is:

RemoteException wrapping System.InvalidCastException: Unable to cast object of type ‘System.Management.Automation.PSCustomObject’ to type ‘System.Management.Automation.PSObject’.
at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Any ideas what I could maybe use instead of “Read text” or “Invoke PowerShell” Activities?

Or is the issue a variable that I should be using?

The Script works in PowerShell by itself but I can´t make UiPath open the PowerShell application to run the script there

I managed to make UiPath open Powershell and run the script like this:


However, I still need to make it work so that if there is available apace <5MB It will open powershell and move “New Folder” under “RemovedFolder” and if there is not available then Report that the drive has enough space.

I have the flowchart set up, is there any activities I can use (like i did in the first step) that detects the available space and then moves the folder for me?

Any “For dummies” explanations highly appreciated :slight_smile: