我需要在两个值之间的文件中更改字符串.我想要做的是,如果我找到值A然后更改为值B,如果我找到值B然后更改为值A.将会有一个消息框弹出,表示该值已更改为[xxxxx]然后背景图片将是也相应改变了.
$path = c:\work\test.xml
$A = AAAAA
$B = BBBBB
$settings = get-content $path
$settings | % { $_.replace($A, $B) } | set-content $path
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何使用IFA然后用B或IFB替换然后替换A.此外,上面的代码将删除文件中的其余内容,并仅将我修改的部分保存回文件.
我正在尝试通过 powershell 发送 slack 消息,但我被卡住了。这是我的脚本。看起来我不能将 $result 用于 -text。
如果有任何低于 15% 或 10% 的可用磁盘空间,我想要做的是向松弛通道发送警报。
我正在使用 Powershell Gallery 中的 PSSlack。
$ErrorActionPreference = "Continue";
$percentCritcal = 15;
$computers = Get-Content "D:\Disk_Usage\ServerList.txt"
$result = foreach($computer in $computers)
{
$disks = Get-WmiObject -ComputerName $computer -Class Win32_LogicalDisk -Filter "DriveType = 3"
$computer = $computer.ToUpper()
foreach($disk in $disks)
{
$Size = $disk.Size
$Freespace = $disk.FreeSpace
$sizeGB = [Math]::Round($Size / 1073741824, 2)
$freeSpaceGB = [Math]::Round($Freespace / 1073741824, 2)
$percentFree = [Math]::Round(($freespace / $size) * 100, 2);
$ResultHash = …Run Code Online (Sandbox Code Playgroud) 我想知道Get-Member与-Properties *在PowerShell中有什么区别。
我做的Get-ADUser AAA | Get-Member和 Get-ADUser AAA -Properties *。
为什么-Properties *给我更多的结果呢Get-Member?
有什么不同?我以为Get-Member是列出与相同的对象的所有属性-Properties *。
我正在使用 Powershell 监视日志文件并过滤某些关键字,需要一些帮助将以下几行放在一起并使其作为警报的自动化任务运行。
Get-Content D:\temp\wow.log -Wait | where {$_ -match "TROUBLE CONNECTING!!"}
$LastWriteTime = (Get-Item $LogFile).LastWriteTime
$CurrentTime = Get-Date
$Range = (New-TimeSpan -Start $LastWriteTime -End $CurrentTime).TotalMinutes
Run Code Online (Sandbox Code Playgroud)
问题:
-wait找到if 的关键词LastWriteTime从到之间的时间范围CurrentTime我试图将其设置为实时警报,不过滤整个日志,而仅过滤最新事件。
如果我想将其安排为任务而不输出到屏幕,我有哪些选择?
这是日志文件中的消息
WARN server comment 2021-06-11 02:21:01 - - - - - 2.0650160216E7 - - - - - - - - PushPublishRTMP.Reconnector[url]: TROUBLE CONNECTING!! Retrying in 60 seconds. app:live/_definst_
Run Code Online (Sandbox Code Playgroud) 我有一个 HTA 文件,它打开一个文本框,允许用户输入文件夹的路径,然后将其保存到文本文件中。
但是当我尝试使用第二个按钮运行批处理时,它给了我一个错误代码
<html>
<head>
<title>Files Sync </title>
<HTA:APPLICATION
APPLICATIONNAME="Files Sync"
ID="RY"
VERSION="1.0"/>
</head>
<script language="vbscript">
Sub WriteTxt_OnClick()
Dim fso, txt
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.CreateTextFile("\\fs-02\C$\ntfs3\scripts\MexSync\000.txt")
txt.WriteLine document.Submitted_Link_To_Mex.body.value
MsgBox "File Submitted",64,"Selection"
End Sub
Sub SYNC_onClick()
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c C:\work\RLTP_SYNC_MEX\RunChangePS1.bat", 0
' 0 => hide
MsgBox("Success")
End Sub
</script>
<H2>Copy And Paste The Folder Path To Here </H2>
<body>
<form name="Submitted_Link_To_Mex">
<textarea name="body" cols="150" rows="20">
</textarea>
</form>
<br>
<input …Run Code Online (Sandbox Code Playgroud) 我有一个小脚本可以过滤掉过去 7 天内远程 PC 的应用程序和系统的错误日志。
Write-Host "Creating Error Log of Remote PC ......."
[System.Threading.Thread]::CurrentThread.CurrentCulture = New-Object "System.Globalization.CultureInfo" "en-US"
$date = get-date
$range = $date.adddays(-7)
$pcname = Read-Host -Prompt "Please Enter PC name"
Get-WinEvent -ComputerName $pcname -FilterHashtable @{LogName="system","application"; Level=1,2; starttime=$range} |
Select-Object @{label="PC"; expression={"$pcname"}},LogName,levelDisplayName,ProviderName,ID,TimeCreated,message |
Sort-Object logname |
Format-Table -AutoSize |
Out-File C:\Eventlog.txt -width 214748
C:\Eventlog.txt
Run Code Online (Sandbox Code Playgroud)
当它运行时,我会得到一个输入 PC 名称的提示,问题是当脚本完成后,powershell 提示将返回到
PS c:\windows\system32\windowspowershell\v1.0>
Run Code Online (Sandbox Code Playgroud)
如果我想在另一台 PC 上检查日志,我必须关闭当前的 PS 窗口并再次运行我的脚本。
我怎样才能做一个循环,让它在第一次运行完成后再次显示我的 [Enter PC name] 提示?
我正在random用这个例子在 Python 3 上学习函数,得到一个错误作为帖子标题。'dict_keys' object is not subscriptable. 我不确定我哪里做错了dictionary。
import random
outcomes = {
'heads':0,
'tails':0
}
sides = outcomes.keys()
for i in range(100):
outcomes[random.choice(sides)] += 1
print("Heads:", outcomes['heads'])
print("Tails:", outcomes['tails'])
Run Code Online (Sandbox Code Playgroud)
下面是错误输出
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-f58aad35f1b0> in <module>
8
9 for i in range(100):
---> 10 outcomes[random.choice(sides)] += 1
11
12 print('Heads:', outcomes['heads'])
C:\ProgramData\Anaconda3\lib\random.py in choice(self, seq)
260 except ValueError:
261 raise IndexError('Cannot choose from an empty sequence') from None …Run Code Online (Sandbox Code Playgroud)