Unrecognized term when trying to run a Powershell Script inside another

Viewed 25

When I tried to pull data in CSV file to SQL server table using PowerShell script, I am getting the below error. Please let me know why I am getting this issue:

PS C:\Users\OneDrive - DTCC\Documents\Powershell_csv_to_SQL> C:\Users\OneDrive - DTCC\Documents\Powershell_csv_to_SQL\Wrkstation_RegDate.ps1
. : The term '..\..\Global\Production\Globals.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\OneDrive - DTCC\Documents\Powershell_csv_to_SQL\Workstation_RegDate.ps1:21 char:3
+ . ..\..\Global\Production\Globals.ps1; Start-IngestorTranscript
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (..\..\Global\Production\Globals.ps1:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : CommandNotFoundException**

Below code is what I am using:

 # Input parameters

 param( 
 # If this is true, then this is an 'official' import that was done automatically.
 [bool] $scheduled = $false,
 [bool] $isExtractionOnly = $false      
 );

 # This prevents errors due to errant keystrokes
 Set-StrictMode -Version Latest
 $ErrorActionPreference = "Stop"


 # include global functions and startup routine
 . ..\..\Global\Production\Globals.ps1; Start-IngestorTranscript
 . ..\..\Global\Production\Startup.ps1

 # This is ISSSDW-Database.Warehouse.Feeds.ID
 #$feedID = 10007;

 # When script is run
 $now = $globals.RanOn

 # do or do not, there is no
 try 
 {
  if (-not $isExtractionOnly) 
  {    
    # This is a destructive load process as PF said I would be getting all the data each day
    $step = Set-Step "Drop loader table..." 
    $sqltables = @( "Tripwire_Workstation_RegDate" )
    $sql = ""
    foreach ($sqltable in $sqltables)
    {
        $sql += "
            
            -- Drop table Loader if exists
            IF OBJECT_ID('dbo.$($sqltable)_Loader') IS NOT NULL BEGIN; DROP TABLE 
    dbo.$($sqltable)_Loader; PRINT 'Dropped;'; END ELSE PRINT 'Does not exist';

        "
    }
    Invoke-Sqlcmd -ServerInstance "." -Database "SE_COMP_PROD" -Query $sql -ErrorAction Stop - 
 Verbose
    Set-Location $globals.ThisIngestorPath
   }
  $step = Set-Step "Clearing any existing files from the working folder..." 
  Remove-FilesFromTempPath

  $copyPath =  "$($globals.FeedsDrop_BasePath)\wrkstation_RegDate_2022-09-13.csv"
  $step = Set-Step "Copying files into $($globals.WorkingTempFolder)..." 
  $file = Get-Item $copyPath | Sort-Object -Property LastWriteTime -Descending | Select-Object 
 -First 1

 # Quit with error if nothing can be done
 if ($null -eq $file) { throw "No files were found to process." }

 Copy-Item $file $($globals.WorkingTempFolder)

# Copy Extracts
Get-ChildItem $globals.WorkingTempFolder -Recurse | ForEach-Object { Copy-Extract $_.FullName 
 $extractionPath }

 $lastitemProcessed = $null

 $raw = Import-Csv "$($globals.WorkingTempFolder)\*.csv" -Delimiter ','
 $data = @()
 foreach ($i in $raw)
 {    

    $Error.Clear() # Remove unnecessary noise from error reports

    $filename = $file.Name
    $resourceDate = $file.LastWriteTime

    $lastItemProcessed = $i
    $iid = [guid]::NewGuid()

    $o = [pscustomobject]@{

                _CreatedOn = $now
                _BatchID = $batchInfo.BatchID
                _Resource = $filename
                _ResourceDateTime = $resourceDate
                _IngestionID = $lid
                Hostname = $i.'Hostname'
                LastRegistrationDate = $i.'LastRegistrationDate'

    }

    $data += $o
    }

    $Error.Clear() # Remove unnecessary noise from error reports
    $lastItemProcessed = $null # anything that happens after this is not reliant on the last 
   item processed above

    }
    catch
  {
  # Borked
  $quitWithError = $true
  $err = "!!! Import has failed. An error occurred while performing step ""$step"": $Error"
  if ($null -ne $lastItemProcessed) { $err += "`nLast item processed: $($lastitemProcessed | 
 ConvertTo-Json)" }
 Write-Host $err
 if (-not $isExtractionOnly) 
 {
    # Write the result to the database, screen, and set that we're exiting with an error code 
  after the finally block runs
    EndBatch $batchInfo.FeedID $batchInfo.BatchID $err
   }    
 }
 finally
 {
 # cleanup all files in temp older than a day old; do this because the output from mars is 
 about 400 MB as of 20181121
 Write-Host "Cleaning up temporary files older than 31 day old."
 CleanupTempFiles 31

  # quit with an error status if we had a problem
  Stop-Ingestor $batchInfo $scheduled $reason (-not $quitWithError) $err $true $(if 
  ($quitWithError) { 3 } else { 0 })
   }
0 Answers
Related