Quota error check

Anonymous
2024-02-03T15:49:56+00:00

I'm copying a large number of folders from one server to another. Unfortunately the destination server has  the disk and the volume different (so I can't make a mirror copy with the same path..) With a little patience I can create the list of powershell commands to create the quotas on the destination server

New-FsrmQuota -Path "D:\Vol01\folder1" -Size2GB -Template "QMPA"

Using New-FsrmQuota  by "running" from  powershell ISE  I cannot clearly see/verify the errors (example: the folder does not exist or the path does not exist) especially if the quotas to set are a large number (as 800) 

I was wondering if there is a way with powershell to  verify errors and have a list of unexecuted quotas, the type of error and the corresponding powershell command.

Windows Server Remote and virtual desktops PowerShell

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question. To protect privacy, user profiles for migrated questions are anonymized.

0 comments No comments
{count} votes

20 answers

Sort by: Most helpful
  1. Anonymous
    2024-02-04T11:02:25+00:00

    I am not an expert, so I was thinking to do someting like that

    $Quotas = @( "New-FsrmQuota -Path "D:\Vol01\folder1" -Size2GB -Template "QMPA" , "New-FsrmQuota -Path "D:\Vol02\folder2" -Size2GB -Template "QMPA" , "New-FsrmQuota -Path "D:\Vol03\folder3" -Size3GB -Template "QMPA" , "New-FsrmQuota -Path "D:\Vol03\folder4" -Size1GB -Template "QMPA" )

    foreach($Quota in $Quotas){
        New-FsrmQuota = $Quota
    }
    

    but I don't know how to add a check to verify what are the unexecuted quotas, (the type of error and the corresponding folder not setup)

    0 comments No comments
  2. Anonymous
    2024-02-05T06:24:31+00:00

    Hi Marc_live,

    PowerShell will throw an exception by default when a command fails to run. If you want to handle the exceptions you can use the try/catch blocks.

    about Try Catch Finally - PowerShell | Microsoft Learn

    1 person found this answer helpful.
    0 comments No comments
  3. Anonymous
    2024-02-05T09:31:44+00:00

    Thank you Ian_Xue,

    you are perfectly right (as usual ), powershell by default shows errors ....but in my case as I have to setup often about 500/700 entries won't be easy after powershell does the job check in the long list all errors and every time I have the feeling I missed someone.

    Will be not bad have a list of all errors, because in that way it will be easier for me to check the errors (error example below).

    PS C:\WINDOWS\system32> New-FsrmQuota -Path "M:\Vol09\SALES" -Size 1GB

    New-FsrmQuota : 0x80045303, The specified object already exists.

    At line:1 char:1

    + New-FsrmQuota -Path "M:\Vol09\SALES" -Size 1GB

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : ResourceExists: (MSFT_FSRMQuota:Root/Microsoft/.../MSFT_FSRMQuota) [New-FsrmQuota], CimException

    + FullyQualifiedErrorId : MI RESULT 11,New-FsrmQuota

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2024-02-05T10:17:50+00:00

    I'm not an expert so I have done just a test to see what I was able to do, but I think "try / catch" statement won't help me.

    Running the script below the check stop at the first error stating a generic message: "The specified object already exists"

    Maybe I can solve using  a ultiple Catch Blocks but it will be very hard do that if the commands to test are a very large number.


    # Define the log file path
    $LogFile = "C:\temp\test\AppLog.txt"
    
    # Wrap commands in a try-catch block
    Try {
    
        # PowerShell command that might generate an error
    New-FsrmQuota -Path "D:\Vol01\folder1" -Size2GB -Template "QMPA -ErrorAction Stop
    New-FsrmQuota -Path "D:\Vol02\folder2" -Size2GB -Template "QMPA -ErrorAction Stop
    New-FsrmQuota -Path "D:\Vol03\folder3" -Size3GB -Template "QMPA -ErrorAction Stop
    New-FsrmQuota -Path "D:\Vol03\folder4" -Size1GB -Template "QMPA -ErrorAction Stop
    
    } Catch {
    
        # Log the error message to the log file
        Add-Content -Path $LogFile -Value $("[" + (Get-Date) + "] " + $_.Exception.Message)
    }
    ---------------------
    

    As in my case as I have to setup often about 500/700 entries will be not bad have a list of all detailed errors (instead to check them in the  powershell  outcome   ). This will help me to check the errors ( to avoid I miss someone ).

    0 comments No comments
  5. Anonymous
    2024-02-06T06:44:51+00:00

    Hi Marc_live,

    Since you have 500/700 entries, you may consider saving the path and size of each one in a csv file. Say the CSV file has the column headers path and size,

    "path","size"
    
    "D:\Vol01\folder1","2GB"
    "D:\Vol01\folder2","2GB"
    "D:\Vol01\folder3","3GB"
    "D:\Vol01\folder4","1GB"
    

    the script can be like this.

    $entries = "C:\entries.csv"
    
    Import-CSV -Path $entries | foreach-object {
    
        Try {      
    
            # PowerShell command that might generate an error
    
            New-FsrmQuota -Path $_.path -Size $_.size -Template "QMPA" -ErrorAction Stop  
        } 
    
        Catch {      
    
            # Log the error message to the log file     
    
            Add-Content -Path $LogFile -Value $("[" + (Get-Date) + "] " + $_.Exception.Message) 
    
        }
    
    }
    
    0 comments No comments