Return value from invoke-Command within a scriptblock?

rated by 0 users
This post has 1 Reply | 1 Follower

Not Ranked
Posts 1

Hello, is there a way to return the result or varibel value from a script block? i trying to get return value in $QuotaRConfiguration

Here is the code.

Function Global:Folder\Get-ReplicationPartnerQuotaFoldersConfiguration($Configuration) {

    $QuotaRConfiguration = @{"users" = @{"office" = @{};};

                                                "groups"= @{"office" = @{"departments"  = @{}; 

                                                 "teams"        = @{};

                                                 "projects"     = @{};};};};                                                            

    $RPServer            = [string]($Configuration["office"]["employees"]["userrepserv"]); 

    $FolderQuotaPath     = ([string]$Configuration["office"]["employees"]["userreppath"]+"\*")

    invoke-Command -ComputerName $RPServer -ScriptBlock {

        param($FolderQuotaPath, $QuotaRConfiguration, $RPServer)     

 

        $quotainfo          = New-Object -com Fsrm.FsrmQuotaManager

        $quotainfo.EnumQuotas($FolderQuotaPath) | foreach-object { 

           $QuotaRConfiguration["users"]["office"][[string]($_.Path)]                   = @{"QuotaPath"      = ([string]($_.Path))                                                                                                                                                       "SourceTemplate" = ([string]($_.SourceTemplateName))};

        }

    } -ArgumentList $FolderQuotaPath, $QuotaRConfiguration, $RPServer

  }                                                             

Return $QuotaRConfiguration;

}

 

 

Top 10 Contributor
Posts 635
Microsoft MVP
Top Contributor

Simply change this part:

 $quotainfo.EnumQuotas($FolderQuotaPath) | foreach-object { 

           $QuotaRConfiguration["users"]["office"][[string]($_.Path)]                   = @{"QuotaPath"      = ([string]($_.Path))                                                                                                                                                       "SourceTemplate" = ([string]($_.SourceTemplateName))};

        }

 

to this part:

 $quotainfo.EnumQuotas($FolderQuotaPath) | foreach-object { 

           $QuotaRConfiguration["users"]["office"][[string]($_.Path)]                   = @{"QuotaPath"      = ([string]($_.Path))                                                                                                                                                       "SourceTemplate" = ([string]($_.SourceTemplateName))};

$QuotaRConfiguration

        }

 

So in essence, inside your foreach-object loop, return the $QuotaRConfiguration object. You do not need the "return ..." statement anymore.

Page 1 of 1 (2 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.