powershell

Copy a list of files to a directory

旧巷老猫 提交于 2020-12-29 03:04:53
问题 There is a folder that contains a lot of files. Only some of the files needs to be copied to a different folder. There is a list that contains the files that need to be copied. I tried to use copy-item, but because the target subfolder does not exist an exception gets thrown "could not find a part of the path” Is there an easy way to fix this? $targetFolderName = "C:\temp\source" $sourceFolderName = "C:\temp\target" $imagesList = ( "C:\temp\source/en/headers/test1.png", "C:\temp\source/fr

Copy a list of files to a directory

六眼飞鱼酱① 提交于 2020-12-29 03:03:32
问题 There is a folder that contains a lot of files. Only some of the files needs to be copied to a different folder. There is a list that contains the files that need to be copied. I tried to use copy-item, but because the target subfolder does not exist an exception gets thrown "could not find a part of the path” Is there an easy way to fix this? $targetFolderName = "C:\temp\source" $sourceFolderName = "C:\temp\target" $imagesList = ( "C:\temp\source/en/headers/test1.png", "C:\temp\source/fr

Find files which does not contains selected string

穿精又带淫゛_ 提交于 2020-12-28 07:00:29
问题 I am trying to find all files, which does not contains a selected string. Find files which contains is easy: gci | select-string "something" but I do not have an idea how to negate this statement. 回答1: I'm not sure if it can be done without the foreach-object but this works: gci |foreach-object{if (-not (select-string -inputobject $_ -Pattern "something")){$_}} 回答2: You can use Where-Object ; gci | Where-Object { !( $_ | Select-String "something" -quiet) } 回答3: As mentionend in How do I

How to read a file word by word in power shell?

陌路散爱 提交于 2020-12-27 06:37:20
问题 In this case I am getting an error. Anyone has any idea what's the problem in the code is? 回答1: param( $fileName = "d:\tmp\file.txt", $name = "Alan" ) @' Mohammed 3 4 5 4 Alan 2 1 3 2 Li 3 5 1 3 '@ | Out-File $fileName -Encoding default $hash = Get-Content $fileName | Where-Object {$_} | ForEach-Object { $array = $_ -split "\s+" @{ $array[0] = [Linq.Enumerable]::Average([int[]]($array[1..($array.Count-1)])) } } if ($hash.Keys -contains $name){ return "$name->$($hash.$name)" } else { return "

How to read a file word by word in power shell?

走远了吗. 提交于 2020-12-27 06:36:05
问题 In this case I am getting an error. Anyone has any idea what's the problem in the code is? 回答1: param( $fileName = "d:\tmp\file.txt", $name = "Alan" ) @' Mohammed 3 4 5 4 Alan 2 1 3 2 Li 3 5 1 3 '@ | Out-File $fileName -Encoding default $hash = Get-Content $fileName | Where-Object {$_} | ForEach-Object { $array = $_ -split "\s+" @{ $array[0] = [Linq.Enumerable]::Average([int[]]($array[1..($array.Count-1)])) } } if ($hash.Keys -contains $name){ return "$name->$($hash.$name)" } else { return "

Powershell - Store hash table in file and read its content

放肆的年华 提交于 2020-12-27 06:30:48
问题 As follow-up, suggested by Doug, on my previous question on anonymizing file ( PowerShell - Find and replace multiple patterns to anonymize file) I need to save all hash tables values in single file "tmp.txt" for further processing. Example: after processing the input file with string like: <requestId>>qwerty-qwer12-qwer56</requestId> the tmp.txt file contains: qwerty-qwer12-qwer56 : RequestId-1 and this is perfect. The problem is when working with many strings, in the tmp.txt file there are

Trying to combine replace and new-item in powershell

六月ゝ 毕业季﹏ 提交于 2020-12-27 05:47:24
问题 I have a task to make changes to some Config files in a Directory, and the files that need changing are 7, all starting with "Monitoring_Tran_xx". Within these files there are certain values (TransactionID="01" AgreedResponseTime="500" SearchProfileID="216") that need changing but not present across all 7, and will need to check if they are present before replace or creating them. Also I am trying to insert a new parameter(using new-item) if a certain parameter is equal to a certain value e.g

Trying to combine replace and new-item in powershell

大城市里の小女人 提交于 2020-12-27 05:44:42
问题 I have a task to make changes to some Config files in a Directory, and the files that need changing are 7, all starting with "Monitoring_Tran_xx". Within these files there are certain values (TransactionID="01" AgreedResponseTime="500" SearchProfileID="216") that need changing but not present across all 7, and will need to check if they are present before replace or creating them. Also I am trying to insert a new parameter(using new-item) if a certain parameter is equal to a certain value e.g

Trying to combine replace and new-item in powershell

流过昼夜 提交于 2020-12-27 05:41:34
问题 I have a task to make changes to some Config files in a Directory, and the files that need changing are 7, all starting with "Monitoring_Tran_xx". Within these files there are certain values (TransactionID="01" AgreedResponseTime="500" SearchProfileID="216") that need changing but not present across all 7, and will need to check if they are present before replace or creating them. Also I am trying to insert a new parameter(using new-item) if a certain parameter is equal to a certain value e.g

Trying to combine replace and new-item in powershell

前提是你 提交于 2020-12-27 05:39:15
问题 I have a task to make changes to some Config files in a Directory, and the files that need changing are 7, all starting with "Monitoring_Tran_xx". Within these files there are certain values (TransactionID="01" AgreedResponseTime="500" SearchProfileID="216") that need changing but not present across all 7, and will need to check if they are present before replace or creating them. Also I am trying to insert a new parameter(using new-item) if a certain parameter is equal to a certain value e.g