小编zoo*_*nce的帖子

覆盖输出文件?

我正在将日志文件中的一些错误提取到一个单独的文件中。

我正在搜索的错误定义在一个小块中:

# Define all the error types that we need to search on
$error_6  = "Missing coded entry in table for provider sector category record"
$error_7  = "not a well-formed email address"
$error_8  = "Org Id must not contain invalid characters"
$error_9  = "Missing sub type code for provider type category record"
$error_10 = "Provider sub type"
Run Code Online (Sandbox Code Playgroud)

然后我读入源日志文件并去掉匹配的行。

奇怪的是,如果我将它们转储到单独的文件中,我会在每个文件中得到正确的行数,但是如果我使用同一个文件,我只会得到一行。我认为它会附加到文件中。

这不起作用(只有一行输出):

(Get-Content $path\temp_report.log) | Where-Object { $_ -match $error_6 } |   Set-Content $path\known_errors.log
(Get-Content $path\temp_report.log) | Where-Object { $_ -match …
Run Code Online (Sandbox Code Playgroud)

powershell file append

5
推荐指数
1
解决办法
1万
查看次数

过滤Invoke-RestMethod结果

我通过GET从我的应用程序中提取有关提供者的一些细节Invoke-RestMethod.目前它正在返回有关提供商的所有详细信息.我想只返回活动状态设置为True的提供程序代码.

$acctname = 'user1'
$password = 'secret'

$params = @{uri = 'http://localhost:8080/tryout/settings/provider/providerDetails';
                   Method = 'Get';
                   Headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("$($acctname):$($password)"))
           } #end headers hash table
   } #end $params hash table


# This gets all the basic info ok
$var = invoke-restmethod @params

#show the values in the console
echo $var
Run Code Online (Sandbox Code Playgroud)

它目前返回所有这些细节.我需要的只是代码,如果active-true.

id            : 90
name          : Test 1
active        : True
code          : NOT_STATED
system        : False
objectVersion : 2

id            : 91
name          : …
Run Code Online (Sandbox Code Playgroud)

powershell powershell-2.0

2
推荐指数
1
解决办法
1511
查看次数

标签 统计

powershell ×2

append ×1

file ×1

powershell-2.0 ×1