Trying to Array information into .csv file. I would like to put the member in a csv

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
cgjackson@yahoo.com
Posts: 7
Last visit: Tue Aug 07, 2018 5:16 am

Trying to Array information into .csv file. I would like to put the member in a csv

Post by cgjackson@yahoo.com »

  1. ##Powershell Test
  2.  
  3. ## parameter declarations
  4. param (
  5.     [string]$DateFrom = $( Read-Host "Input Last Date Updated, format YYYY-MM-DD" ),
  6.     [string]$DateTo = $( Read-Host "Input Date to Update To (Leave blank for today), format YYYY-MM-DD" )
  7. )
  8.  
  9. $DateTo = "_$DateTo";
  10. $matches = @()
  11.  
  12. ## WebRequest Section. Deprecated, Use Invoke-WebRequest in PS 3.0 and higher
  13. $HTTPRequest = "https://appstest.mclaneco.com/employee-photo-booth/rest/image/queries/update/activedirectory/$DateFrom$DateTo"
  14.  
  15. $WebRequest = [System.Net.WebRequest]::Create("$HTTPRequest")
  16. $WebRequest.Method = "GET"
  17. $WebRequest.ContentType = "application/json; charset=utf-8"
  18. $Response = $WebRequest.GetResponse()
  19. $ResponseStream = $Response.GetResponseStream()
  20. $ReadStream = New-Object System.IO.StreamReader $ResponseStream
  21. $Data=$ReadStream.ReadToEnd()
  22.  
  23. ## Filters Input and seperates each userId=employeeId, to a PSObject
  24. $matches += $Data | Select-String -Pattern '([a-zA-Z0-9]{3,8})=([0-9]{9})' -AllMatches |
  25. ForEach-Object {$_.matches} |  ForEach-Object {New-Object PSObject -Property @{
  26. UsrID = $($_.groups[1]);
  27. EmpID = $($_.groups[2]);
  28. }};
  29.  
  30.  
  31. Write-Host $HTTPRequest;
  32.  
  33.  
  34. ## Checks to see if the photo directory is available for an employee ID, switch to production file path for final result
  35. ForEach($match in $matches){
  36.     $ChkFile = "\\vserver-appdata01.mclane.mclaneco.com\test_emp_photos$\Photos\$($match.EmpID)";
  37.     $FileExists = Test-Path $ChkFile;
  38.     if($FileExists -eq $True){
  39.         Write-Host "$($match.UsrID) -> $($match.EmpID)"
  40.  
  41.         Write-Host "Has Image Dir";
  42.     }
  43.    
  44. }
Attachments
dPhotoTest.ps1
Works with results window, but I am have problem getting it to a file.
(1.57 KiB) Downloaded 105 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Trying to Array information into .csv file. I would like to put the member in a csv

Post by jvierra »

To get Json data as an object we would normally use "Invoke-WebRequest".
This topic is 6 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked