Power shell script

Need to write a script which:
1. Download the json file (curl request)
2. Rename the file to  YYYYMMDDHHMM_lng.xml
3. Push it to a shared folder (for example //
Benny CaspiIntegrationAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David SankovskySenior SysAdminCommented:
Try this one (It's untested, make sure to do a dry run first)

#Generate TimeStamp

#Set Download Location
$URL = "https://domain.tld/path/to/file.xml"

#Set downloaded file name
$FNAME = "$YEAR"+"$Month"+"$Day"+"$Hour"+"$Minute"+"_lng.xml"
$OUTPATH = "\\network.path.address\shared\folder"

#invoke the command:
Invoke-WebRequest -Uri $URL -OutFile $OUTFILE

Open in new window

Shaun VermaakTechnical SpecialistCommented:
1) If it is just a Get you can just download
2) No need to rename, just download with the correct name
3) No need to copy, download to correct location

$newFileName = "$(get-date -f yyyyMMddHHmm)_lng.xml"
$WebClient = New-Object System.Net.WebClient

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
why are you renaming a json file as .XML?
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

Benny CaspiIntegrationAuthor Commented:
10xs for quick answer.
I get my 'JSON' by running curl to https://poeditor.com/api/:

curl.exe -k -X POST https://poeditor.com/api/ -H Cache-Control=no-cache -H Content-Type="application/json" -F api_token="ttttssssaaaaqqqqzzzzwwwwyyyyxxxx" -F action="export" -F id="123456" -F language=en -F type="key_value_json"

response is:

need to take "https:\/\/poeditor.com\/api\/download\/file\/10b60ec9fd13ff1dfe146590f48388f0" and save it as yyyyMMddHHmm_lng.xml

please assist to write it true
$b=[pscustomobject]@{name="item";value=($curlresponse | convertfrom-json).item} | convertto-xml

Open in new window

Benny CaspiIntegrationAuthor Commented:
explanation to me request:
I get next Output from Invoke-WebRequest -uri 'https://poeditor.com/api/' -Method POST -body $postparams

StatusCode        : 200
StatusDescription : OK
Content           : {"response":{"status":"success","code":"200","message":"OK"},"item":"https:\/\/poeditor.com\/api\/d
RawContent        : HTTP/1.1 200 OK

each time the url is different

I want to copy the URL in 'normal form https:\\poeditor.com\api\...
and run :
$newFileName = "$(get-date -f yyyyMMddHHmm)_lng.xml"
$WebClient = New-Object System.Net.WebClient

How can I do it in 1 script ?
my code would take the response you get and extract the item value (=URL). Your posted script could use that URL to download the XML file.
I don't have curl on my laptop, so I hard-coded the JSON response.
Benny CaspiIntegrationAuthor Commented:
each time the url is different:

StatusCode        : 200
StatusDescription : OK
Content           : {"response":{"status":"success","code":"200","message":"OK"},"item":"https:\/\/poeditor.com\/api\/d
RawContent        : HTTP/1.1 200 OK
                    Pragma: no-cache
                    Content-Length: 148
                    Cache-Control: no-store, no-cache, must-revalidate
                    Content-Type: application/json; charset=utf-8
                    Date: Sun, 01 Apr 2018 21:31:06 GMT
Forms             : {}
Headers           : {[Pragma, no-cache], [Content-Length, 148], [Cache-Control, no-store, no-cache, must-revalidate],
                    [Content-Type, application/json; charset=utf-8]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 148

how to aassign 'customparamater' to 'item' on the fly (in xml format ) ?
and run  

1. Assign the response to the curl command to a variable, $curlresponse
2. run the following statement:
($curlresponse | convertfrom-json).content.item

Open in new window

That should get you the URL string.  You can then use that URL string in your download.
Benny CaspiIntegrationAuthor Commented:
when I run:
$b=[pscustomobject]@{name="item";value=($curlresponse | convertfrom-json).item} | convertto-xml

I get:
PS C:\curl> echo $b

xml                            Objects
---                            -------
version="1.0" encoding="utf-8" Objects

how I can get just the https://url ?
my prior comment:
($curlresponse | convertfrom-json).content.item

Open in new window

Benny CaspiIntegrationAuthor Commented:
additional Powershell Question:
in my script I use $response.Content and get the output not pretty
$response=Invoke-WebRequest -Uri http://tve-web1-dev.corbina.net/api_v3/service/configurations/action/serveByDevice -Method POST -Body $postman -ContentType "application/json"

json","Suggested_recalculation_period ":"7","Suggested_calculation_by_last_x_items ":"20"}}

1.how to show it pretty
2. how to update 1 value in the text
talog/translations/183011410_rus.json with new URL ?
Benny CaspiIntegrationAuthor Commented:
1st question : how to show it pretty - resolved by
Since this question thread is closed, please open a new thread for your new questions.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.