commit 64872554c5785b1ab51477fc698084707b36369a Author: eeckert Date: Fri Mar 22 09:37:32 2024 -0600 phase 1 complete. diff --git a/Asset-Data.ps1 b/Asset-Data.ps1 new file mode 100644 index 0000000..9ed789a --- /dev/null +++ b/Asset-Data.ps1 @@ -0,0 +1,87 @@ +<# Script will grab asset info from InvGate and Extracted Invoice Details #> + +<# +AssetStatus values: +2 - Active +8 - Loaner +9 - Stock +3 - Deleted + + + +#> + +$API_Secret = 'wmFuMl5mEOsn7drmv606vyCbN6c1Z6BIZYjVa5EfdPWRqzVJ4KVXkn28gbXf5KqUxTHZgQsnRnPfnYT88zOCyDu4VlZlIGRcE8jGMOGP5kuAowpVKeMl2JYK1JczCFW1' +$API_ClientID = 'rk5ZnbKVRR0LtJw0BJovkHprkmAgghjSVPCJK4DC' +$AssetMgrURI = "https://mpeengine.is.cloud.invgate.net:443/public-api" +$Locations = '{"links":{"first":"https://mpeengine.is.cloud.invgate.net/public-api/locations/?access_token=zTlzGAHXwJL1BZsQPMlGHmRjb77ASN&page=1","last":"https://mpeengine.is.cloud.invgate.net/public-api/locations/?access_token=zTlzGAHXwJL1BZsQPMlGHmRjb77ASN&page=1","next":null,"prev":null},"data":[{"type":"Location","id":"24","attributes":{"name":"AWS","full_path":"Cloud > AWS","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":{"type":"Location","id":"23"}},"configuration_item":{"data":null}}},{"type":"Location","id":"25","attributes":{"name":"Azure","full_path":"Cloud > Azure","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":{"type":"Location","id":"23"}},"configuration_item":{"data":null}}},{"type":"Location","id":"28","attributes":{"name":"Calgary","full_path":"Calgary","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"23","attributes":{"name":"Cloud","full_path":"Cloud","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"32","attributes":{"name":"Edmonton","full_path":"Edmonton","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"36","attributes":{"name":"Grande Prairie","full_path":"Grande Prairie","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"27","attributes":{"name":"Lethbridge","full_path":"Lethbridge","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"47","attributes":{"name":"Lethbridge North","full_path":"Lethbridge North","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"53","attributes":{"name":"Medicine Hat","full_path":"Medicine Hat","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"51","attributes":{"name":"Red Deer","full_path":"Red Deer","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"48","attributes":{"name":"Regina","full_path":"Regina","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"50","attributes":{"name":"Saskatoon","full_path":"Saskatoon","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"49","attributes":{"name":"Saskatoon","full_path":"Saskatoon","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"54","attributes":{"name":"Vancouver","full_path":"Vancouver","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}},{"type":"Location","id":"52","attributes":{"name":"Winnipeg","full_path":"Winnipeg","description":null,"content_type":{"id":109}},"relationships":{"parent":{"data":null},"configuration_item":{"data":null}}}],"meta":{"pagination":{"page":1,"pages":1,"count":15}}}' | ConvertFrom-Json +$locations_table = @() +$assets = @() + + +foreach ($location in $Locations.data) { + $temp = [PSCustomObject]@{ + ID = $location.id + Name = $location.attributes.name + } + $locations_table += $temp + +} + + +function Auth { + param ( + $API_Secret_Auth, $API_ClientID_Auth + ) + + $auth_Header = @{ + 'Content-Type' = "application/x-www-form-urlencoded" + } + $auth_Body = "grant_type=client_credentials&client_id=$API_ClientID_Auth&client_secret=$API_Secret_Auth" + + $AuthURI = 'https://mpeengine.is.cloud.invgate.net:443/oauth2/token/' + $resp = Invoke-WebRequest $AuthURI -Method POST -Headers $auth_Header -Body $auth_Body + + return ($resp.Content | ConvertFrom-Json) +} + + + +# Get bearer token if it doesn't exist or is expired. + +if (!($b_token) -or $b_token.expires_in -lt (get-Date)) { + $b_token = Auth -API_Secret_Auth $API_Secret -API_ClientID_Auth $API_ClientID + $b_token.expires_in = (Get-Date).AddSeconds($b_token.expires_in) # Change to date format. +} + +$req_Headers = @{ + Authorization = "Bearer " + $b_token.access_token + 'Content-Type' = 'application/vnd.api+json' +} + +# Find all active, Loaner, or Stock assets. +$queryString = '?status_ids=2,8,9' + +$RequestURI = $AssetMgrURI + "/v2/assets-lite/" + $queryString +$Response = Invoke-WebRequest -Uri $RequestURI -Headers $req_Headers +do { + $assets += ($Response.Content | ConvertFrom-Json).results + $RequestURI = ($Response.Content | ConvertFrom-Json).next + $Response = Invoke-WebRequest -Uri $RequestURI -Headers $req_Headers + +} while ($RequestURI) + +# Get Locations +# $queryString = '?access_token=' + $b_token.access_token #V1 API's need token in the URL instead of header... +# $RequestURI = $AssetMgrURI + "/locations/" + $queryString +# $Response = Invoke-WebRequest -Uri $RequestURI -Headers $req_Headers + +foreach ($asset in $assets) { + $matched = $locations_table | where ID -eq $asset.location + $asset.location = $matched.Name +} + +$ExportData = $assets | select id, name, serial, location, Manufacturer, model, "InvoiceNumber" +$ExportData | Export-Csv .\AssetList.csv + +# Invoke-WebRequest -Uri $RequestURI -method GET -ContentType application/json \ No newline at end of file diff --git a/PowerAutoMateFlow-Main.txt b/PowerAutoMateFlow-Main.txt new file mode 100644 index 0000000..56ea066 --- /dev/null +++ b/PowerAutoMateFlow-Main.txt @@ -0,0 +1,12 @@ +File.ReadFromCSVFile.ReadCSV CSVFile: $'''C:\\Users\\eeckert\\Scripting\\AssetList.csv''' Encoding: File.CSVEncoding.UTF8 TrimFields: True FirstLineContainsColumnNames: True ColumnsSeparator: File.CSVColumnsSeparator.SystemDefault CSVTable=> AssetList +SET PathToInvoices TO $'''M:\\IT\\Vendors\\Dell\\01_Invoices''' +Folder.GetFiles Folder: PathToInvoices FileFilter: $'''*.pdf''' IncludeSubfolders: True FailOnAccessDenied: False SortBy1: Folder.SortBy.CreationTime SortDescending1: True SortBy2: Folder.SortBy.NoSort SortDescending2: False SortBy3: Folder.SortBy.NoSort SortDescending3: False Files=> InvoiceFiles +LOOP FOREACH CurrentItem IN InvoiceFiles + Pdf.ExtractTextFromPDF.ExtractText PDFFile: CurrentItem.FullName DetectLayout: False ExtractedText=> ExtractedPDFText + Pdf.ExtractTablesFromPDF.ExtractTablesFromPage PDFFile: CurrentItem.FullName PageNumber: 1 MultiPageTables: True SetFirstRowAsHeader: False ExtractedPDFTables=> ExtractedPDFTables + IF IsEmpty(ExtractedPDFText) THEN + NEXT LOOP + END + CALL 'Dell Service Tags' +END +File.WriteToCSVFile.WriteCSV VariableToWrite: AssetList CSVFile: $'''C:\\Users\\eeckert\\Scripting\\AssetList-Updated.csv''' CsvFileEncoding: File.CSVEncoding.UTF8 IncludeColumnNames: True IfFileExists: File.IfFileExists.Overwrite ColumnsSeparator: File.CSVColumnsSeparator.SystemDefault diff --git a/PowerAutomateFlow-Dell.txt b/PowerAutomateFlow-Dell.txt new file mode 100644 index 0000000..796eb06 --- /dev/null +++ b/PowerAutomateFlow-Dell.txt @@ -0,0 +1,13 @@ +Text.ParseText.RegexParseForFirstOccurrence Text: ExtractedPDFText TextToFind: $'''PO Number\\/Réf client: (\\S+)''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position Match=> Match +Text.CropText.CropTextAfterFlag Text: Match FromFlag: $''':''' IgnoreCase: True CroppedText=> CroppedText IsFlagFound=> IsFlagFound +SET PONumber TO CroppedText +Text.ParseText.RegexParseForFirstOccurrence Text: ExtractedPDFText TextToFind: $'''No de facture: (\\S+)''' StartingPosition: 0 IgnoreCase: False OccurrencePosition=> Position Match=> Match +Text.CropText.CropTextAfterFlag Text: Match FromFlag: $''':''' IgnoreCase: True CroppedText=> CroppedText IsFlagFound=> IsFlagFound +SET InvoiceNumber TO CroppedText +Text.ParseText.RegexParse Text: ExtractedPDFText TextToFind: $'''\\b(?=.*\\d)[A-Z0-9]{7}\\b''' StartingPosition: 0 IgnoreCase: False OccurrencePositions=> Positions Matches=> Matches +LOOP FOREACH MatchedTags IN Matches + Variables.FindOrReplaceInDataTable.FindItemInDataTableByColumnIndex DataTable: AssetList AllMatches: True ValueToFind: MatchedTags MatchCase: False MatchEntireCellContents: False ColumnNameOrIndex: $'''serial''' DataTableMatches=> DataTableMatches + LOOP FOREACH Asset_Match IN DataTableMatches + Variables.ModifyDataTableItem DataTable: AssetList ColumnNameOrIndex: $'''InvoiceNumber''' RowIndex: Asset_Match['Row'] Value: InvoiceNumber.Trimmed + END +END