This is dirty but should get the idea out there. This was a tab delimeted file not a csv but reading a csv is pretty simple.
$accessId = ''
$accessKey = ''
$ParentFolder = '5937'
$httpVerb = 'POST'
$resourcePath = '/device/groups'
$url = 'https://PORTAL.logicmonitor.com/santaba/rest' + $resourcePath
$Locations = Import-Csv C:\Users\user\Downloads\folders.txt -Delimiter "`t" -Header "SiteName","Street","City","State","Zip"
foreach ($Location in $Locations) {
Write-Host $Location.SiteName
$data = '{"name":"' + $Location.SiteName + '","parentId":' + $ParentFolder + ',"customProperties":[{"name":"location","value":"' + $Location.Street + ", " + $Location.City + ", " + $Location.State + " " + $Location.Zip + '"}]}'
$epoch = [Math]::Round((New-TimeSpan -start (Get-Date -Date "1/1/1970") -end (Get-Date).ToUniversalTime()).TotalMilliseconds)
<# Concatenate Request Details #>
$requestVars = $httpVerb + $epoch + $data + $resourcePath
<# Construct Signature #>
$hmac = New-Object System.Security.Cryptography.HMACSHA256
$hmac.Key = [Text.Encoding]::UTF8.GetBytes($accessKey)
$signatureBytes = $hmac.ComputeHash([Text.Encoding]::UTF8.GetBytes($requestVars))
$signatureHex = [System.BitConverter]::ToString($signatureBytes) -replace '-'
$signature = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($signatureHex.ToLower()))
<# Construct Headers #>
$auth = 'LMv1 ' + $accessId + ':' + $signature + ':' + $epoch
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization",$auth)
$headers.Add("Content-Type",'application/json')
$response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers -Body $data
}