我想替换$test
包含的字符串,$folder
没有语法错误但没有替换:
$folder = 'c:\test'
$test = 'c:\test\subtest\' -replace $folder, ""
Run Code Online (Sandbox Code Playgroud)
$ test仍然包含'c:\ test\subtest \'
我有以下代码,
Write-Output "$(Get-Content $alerfile | Select-String $(Get-Date (Get-Date).AddDays(-1) -Format $filtdate) -Context 0,1000000)"
Run Code Online (Sandbox Code Playgroud)
我只需要返回行首的字符串,我尝试过:
Write-Output "$(Get-Content $alerfile | Select-String ^$(Get-Date (Get-Date).AddDays(-1) -Format $filtdate) -Context 0,1000000)"
Run Code Online (Sandbox Code Playgroud)
但这不起作用。
如果时间是在上午8:00到下午5:30之间,并且其余时间没有发送邮件,有人可以提一下如何执行sendmail功能吗?
基本上像这样的伪作品.
if(time between 8:00 AM and 5:30 PM)
{
send mail
{
else
{
do nothing
}
Run Code Online (Sandbox Code Playgroud)
更像这样
[int]$hour = get-date -format HH
If($hour -lt 8 -or $hour -gt 17)
{
Run Code Online (Sandbox Code Playgroud) 想象一下,您创建了返回布尔值的函数(例如Set-SomeConfiguration
).然后,你用它调用该函数
Start-Job -Scriptblock { Set-SomeConfiguration -ComputerName $computer }
Run Code Online (Sandbox Code Playgroud)
有没有办法检索由Set-SomeConfiguration
?生成的布尔值?
我在目录中有以下2个文件,我想更改:
a.exe.deploy
⇒ a.exe
b.config.deploy
⇒b.config
我看到ren
了这方面的用例,但我不能让它修剪最后一部分.
我正在尝试通过 PowerShell 解析此 JSON 内容:
gc .\release.json | ConvertFrom-Json
Run Code Online (Sandbox Code Playgroud)
release.json
将有类似的内容如下:
{
"source": 2,
"id": 3487,
"environments": [
{
"id": 11985,
"variables": {
"Var1": { "value": "val1" },
"Var2": { "value": "val2" },
"var3": { "value": "val3" }
}
},
{
"id": 13797,
"variables": {
"Var1": { "value": "val1" },
"Var2": { "value": "val2" },
"var3": { "value": "val3" },
"var4": { "value": "val4" }
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
为了获得如下所示的输出,我可以在每个环境中拥有许多变量,并且可以拥有多个环境。最终我需要将其导入 Excel 并进行分析。