Multiple Functions in one Script - Not waiting for first function to complete

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Kawika Moss Kawika Moss 1 year, 9 months ago.

  • Author
    Posts
  • #24568
    Profile photo of Kawika Moss
    Kawika Moss
    Participant

    I have a script that when it runs it calls several functions, I've added a new one to do an additional check and the function is not getting a chance to complete so I can see it's return value before going on to the next one...

    
    		Foreach ($EvidSet in $EvidenceList)
    		{
    			# Verify case data does not exist before creating the case
    			$VerifyCaseData = NuixCaseFiles_Copy-Move-Verify $ServerInstance $ProjectDBName $EvidSet $LogsDirectory "VerifyCaseData" "CaseData-Exist" "$PsScriptPath\Functions" -Verbose
    			Write-Verbose -message "Case Data Exists: $VerifyCaseData"
                           ###################### THE ABOVE FUNCTION IS WHAT IS BEING SKIPPED BASICALLY, I SEE IT ATTEMPT TO RUN, BUT THE NEXT FUNCTION BEGINS BEFORE i CAN GET THE VERBOSE OUTPUT ############
    			
    			# Get search available license servers available in the pool, then assign first available if license tests as OK
    			$QueryResult = Get-QueryOutput -ServerInstance 'HLPROJD01' -DatabaseName 'AdminDB' -QueryText "SELECT * FROM   [ADMIN].[NuixLicenseConnectionStringGet](1, '$HostNuixVersion');"
    			$NewResults = $QueryResult  | Select-object  -ExpandProperty  ServerName
    			$LicenseServernames = $NewResults.Split(',')
    			$NUIXLicenseServername = Get-NuixLicenseServer -ServerName $LicenseServernames -HostNuixVersion $HostNuixVersion -Verbose
    			Write-Verbose -Message " Available License Servers`: $NUIXLicenseServername"
    			
    			$ParamList = @{
    			'PsScriptPath' = "$PsScriptPath\Functions";
    			'ServerInstance' = ($ProjConnString.ServerName);
    			'DatabaseName' = ($ProjConnString.DatabaseName);
    			'EvidenceSet' = $EvidSet;
    			'InstalledNuixVersion' = "$HostNuixVersion";
    			'NuixApplication' = "$NuixConsoleApp";
    			'SessionNum' = $SessionNum;
    			'SettingCategory' = "3E7C559A-FC2F-46BF-8282-77945231BA89";
    			'NuixOperation' = 'Processing';
    			'LogsDirectory' = $LogsDirectory; 
    			'TempDirectory' = $TempDirectory;			
    			## Added parameter for Nuix License work
    			'NUIXLicenseServerName' = $NUIXLicenseServerName }
    			
    			$AuditTotals = RunNuixOperation @ParamList -Verbose
    
    			$AuditResults = $AuditResults + $AuditTotals
    			
    			# Copy Case files to the Network
    			$MoveToNetwork = NuixCaseFiles_Copy-Move-Verify $ServerInstance $ProjectDBName $EvidSet $LogsDirectory "CaseCreate" "ToNetwork" "$PsScriptPath\Functions" -Verbose
    			Write-Verbose -message "Move to Network: $MoveToNetwork"
    			
    		}
    
    

    Any ideas why??

  • #24570
    Profile photo of TomBaker
    TomBaker
    Participant

    Write-Verbose does not write to the verbose stream unless $VerbosePreference is changed to 'Continue' or your above snip is from an advanced function which implements [cmdletbinding()] and you have provided -verbose.
    To make Write-Verbose always write the verbose stream you must also pass it -Verbose

    Write-Verbose -message "Case Data Exists: $VerifyCaseData" -Verbose
  • #24576
    Profile photo of Kawika Moss
    Kawika Moss
    Participant

    good catch...thanks...it takes another set of eyes lol

You must be logged in to reply to this topic.