powershell

Run a script via FTP connection from PowerShell

二次信任 提交于 2021-02-08 08:22:20
问题 I have made a script that does a really basic task, it connects to a remote FTP site, retrieves XML files and deletes them afterward. The only problem is that in the past we lost files because they were added when the delete statement was run. open ftp.site.com username password cd Out lcd "E:\FTP\Site" mget *.XML mdel *.XML bye To prevent this from happening, we want to put a script on the FTP server ( rename-files.ps1 ). The script will rename the *.xml files to *.xml.copy . The only thing

VERY large XML files in Powershell

血红的双手。 提交于 2021-02-08 08:22:20
问题 For very large text files we have the option of using StreamReader and StreamWriter, which then allows for doing find/replace on a line by line bases. However, I have an XML file where I need to do find/replace with a little more control, for example find/replace on a value in a particular node that is a child node of another node with a particular attribute and value. So, rather complex to try to parse line by line, and super easy to deal with when using an XML document. However, my file is

VERY large XML files in Powershell

眉间皱痕 提交于 2021-02-08 08:21:10
问题 For very large text files we have the option of using StreamReader and StreamWriter, which then allows for doing find/replace on a line by line bases. However, I have an XML file where I need to do find/replace with a little more control, for example find/replace on a value in a particular node that is a child node of another node with a particular attribute and value. So, rather complex to try to parse line by line, and super easy to deal with when using an XML document. However, my file is

Unable to change encoding of text files in Windows

旧巷老猫 提交于 2021-02-08 08:19:10
问题 I have some text files with different encodings. Some of them are UTF-8 and some others are windows-1251 encoded. I tried to execute following recursive script to encode it all to UTF-8 . Get-ChildItem *.nfo -Recurse | ForEach-Object { $content = $_ | Get-Content Set-Content -PassThru $_.Fullname $content -Encoding UTF8 -Force} After that I am unable to use files in my Java program, because UTF-8 encoded has also wrong encoding, I couldn't get back original text. In case of windows-1251

How to compare JSON in powershell

匆匆过客 提交于 2021-02-08 07:51:56
问题 I have a requirement where I need to compare JSON object from a file to the JSON message which comes into Anypoint MQ queue. I am able to get the message from the queue. I have used below script but it is not working. I did both -eq and Compare-Object but they are not working. $po_ps_output = $filemessagecontent | ConvertFrom-Json $po_python_output = $mqmessagecontent.body | ConvertFrom-Json $result = $po_ps_output -eq $po_python_output 回答1: If you just want to know if the two JSON-originated

How to compare JSON in powershell

那年仲夏 提交于 2021-02-08 07:51:53
问题 I have a requirement where I need to compare JSON object from a file to the JSON message which comes into Anypoint MQ queue. I am able to get the message from the queue. I have used below script but it is not working. I did both -eq and Compare-Object but they are not working. $po_ps_output = $filemessagecontent | ConvertFrom-Json $po_python_output = $mqmessagecontent.body | ConvertFrom-Json $result = $po_ps_output -eq $po_python_output 回答1: If you just want to know if the two JSON-originated

How do I make a folder with today's date and then copy a file to it?

元气小坏坏 提交于 2021-02-08 07:37:21
问题 I am trying to automate my day, part of which is creating a daily work folder and copying a 'Job Notes' file which I use, rename and save per job, repeat again the next day. I found a script to create a folder based on today's date, which works, and I've obviously found examples of how to copy a file. What I'm looking for is to combine the two. I just need something basic. Here is the code I have for the folder creation. I just don't know what to add to the "copy file" action to make it use

How do I make a folder with today's date and then copy a file to it?

走远了吗. 提交于 2021-02-08 07:37:08
问题 I am trying to automate my day, part of which is creating a daily work folder and copying a 'Job Notes' file which I use, rename and save per job, repeat again the next day. I found a script to create a folder based on today's date, which works, and I've obviously found examples of how to copy a file. What I'm looking for is to combine the two. I just need something basic. Here is the code I have for the folder creation. I just don't know what to add to the "copy file" action to make it use

Invoke-Webrequest gets 401 on POST but not on GET with Basic Auth

﹥>﹥吖頭↗ 提交于 2021-02-08 07:35:48
问题 I have a dev site with Basic Auth enabled. I am get to GET a page using the following to add basic auth to the headers: $creds = "$($BASIC_AUTH_USER):$($BASIC_AUTH_PASS)" $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($creds)) $basicAuthValue = "Basic $encodedCreds" $headers = @{ Authorization = $basicAuthValue } $login = Invoke-WebRequest $url -SessionVariable session -UseBasicParsing -Headers $headers But I am unable to post to the same URL: $fields

Trouble parsing string to object with PowerShell

流过昼夜 提交于 2021-02-08 07:33:54
问题 I have a string with structured data (see below). I need to take this string and convert it to an object, so I can export it to .csv (or whatever else is requested of me). I ran the following code: $data = $string -replace "\s*:\s*","=" But my output looks like this: City=Country=Department=DisplayName=John Doe DistinguishedName=CN=John Doe, CN=Users, DC=domain, DC=com EmailAddress=jdoe@domain.com Enabled=False Fax=GivenName=John MobilePhone=Name=John Doe ObjectClass=user ObjectGUID=cdb9a45c