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

Ask your Windows 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.
Locked
User avatar
cgjackson@yahoo.com
Posts: 7
Joined: Wed Mar 01, 2017 12:54 pm

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

Post by cgjackson@yahoo.com » Thu May 25, 2017 8:11 am

Code: Select all

##Powershell Test

## parameter declarations
param (
[string]$DateFrom = $( Read-Host "Input Last Date Updated, format YYYY-MM-DD" ),
[string]$DateTo = $( Read-Host "Input Date to Update To (Leave blank for today), format YYYY-MM-DD" )
)

$DateTo = "_$DateTo";
$matches = @()

## WebRequest Section. Deprecated, Use Invoke-WebRequest in PS 3.0 and higher
$HTTPRequest = "https://appstest.mclaneco.com/employee-photo-booth/rest/image/queries/update/activedirectory/$DateFrom$DateTo"

$WebRequest = [System.Net.WebRequest]::Create("$HTTPRequest")
$WebRequest.Method = "GET"
$WebRequest.ContentType = "application/json; charset=utf-8"
$Response = $WebRequest.GetResponse()
$ResponseStream = $Response.GetResponseStream()
$ReadStream = New-Object System.IO.StreamReader $ResponseStream
$Data=$ReadStream.ReadToEnd()

## Filters Input and seperates each userId=employeeId, to a PSObject
$matches += $Data | Select-String -Pattern '([a-zA-Z0-9]{3,8})=([0-9]{9})' -AllMatches |
ForEach-Object {$_.matches} | ForEach-Object {New-Object PSObject -Property @{
UsrID = $($_.groups[1]);
EmpID = $($_.groups[2]);
}};


Write-Host $HTTPRequest;


## Checks to see if the photo directory is available for an employee ID, switch to production file path for final result
ForEach($match in $matches){
$ChkFile = "\\vserver-appdata01.mclane.mclaneco.com\test_emp_photos$\Photos\$($match.EmpID)";
$FileExists = Test-Path $ChkFile;
if($FileExists -eq $True){
Write-Host "$($match.UsrID) -> $($match.EmpID)"

Write-Host "Has Image Dir";
}

}
Attachments
dPhotoTest.ps1
Works with results window, but I am have problem getting it to a file.
(1.57 KiB) Downloaded 36 times

User avatar
jvierra
Posts: 13792
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Thu May 25, 2017 9:53 am

To get Json data as an object we would normally use "Invoke-WebRequest".

Locked