我正在使用Get-EventLog来设置变量,然后使用事件ID描述设置另一个变量.然后我使用blat.exe将此信息通过电子邮件发送给组.
描述包含引号.引号导致blat退出并出错.
有没有办法从event.Message中删除引号并用空格或其他东西替换它们?
PowerShell新秀在这里.我试图让Select-String解析下面的变量.
我正在调用一个外部程序,它将所有内容记录到标准输出.这是我正在使用的备份同步软件.输出是很多信息,如源,目标,复制的文件,更改的文件等.我只关心标准输出中的一些项目.我正在采用标准输出并尝试解析我关心的几个项目,所以我只看到那些,而不是其他50条其他信息.
这是代码:
$procInfo = New-Object System.Diagnostics.ProcessStartInfo
$procInfo.FileName = "C:\Program Files\Siber Systems\GoodSync\gsync.exe"
$procInfo.RedirectStandardError = $true
$procInfo.RedirectStandardOutput = $true
$procInfo.UseShellExecute = $false
$procInfo.Arguments = "/progress=yes /exit sync DroboBackup"
$proc = New-Object System.Diagnostics.Process
$proc.StartInfo = $procInfo
$proc.Start() | Out-Null
(Get-Date -format T) + ": Backup Process Running. Please Stand By..."
$proc.WaitForExit()
if ($proc.ExitCode -eq 0)
{
"GoodSync Reported: Analyze or Sync Successfully Completed."
} elseif ($proc.ExitCode -eq 1)
{
"GoodSync Error: Analyze had Terminal Errors. Did gsync.exe close abruptly?"
} elseif ($proc.ExitCode …Run Code Online (Sandbox Code Playgroud) 我试图让我简单的"滚动到顶部"图像显示并根据您离页面顶部有多远而消失.例如,假设距离顶部100像素.
这就是我所拥有的.它似乎可以向下滚动,图像div淡入.
当我滚动回到顶部时,div不会fadeOut.有小费吗?
$(window).scroll(function() {
if ($(this).scrollTop()>100)
{
$('#toTop').fadeIn();
}
else
{
$('.#toTop').fadeOut();
}
});
Run Code Online (Sandbox Code Playgroud) 我希望根据是否是营业时间来运行条件声明.我们的营业时间是08:00至17:00.我有下面的脚本,但它不起作用.
我想(Get-Date).tostring('%H')与小时数进行比较.
我也尝试过((Get-Date).hour -ge 17)它仍然失败了.
有什么想法吗?
while ($loop -eq 1) {
Write-Host "Running"
# Get last write timestamp
$lastwrite = [datetime](Get-ItemProperty -Path $source -Name LastWriteTime).lastwritetime
if ( ((Get-Date).tostring('%H') -le "8" ) -and ( (Get-Date).tostring('%H') -ge "17" ) ) {
# Do nothing, it is outside of the time window
Write-Host "Nothing to do, outside of business hours"
} elseif (($lastwrite -le (Get-Date).addMinutes(-$ageMinutes)) -and ((Get-Date).tostring('%H') -ge "8" -and (Get-Date).tostring('%H') -le "17")) {
# If it's older than …Run Code Online (Sandbox Code Playgroud) 我有一个来自内部网站报告的服务器名称动态列表。我希望 PowerShell 从 URL 获取此列表,然后将其用作我可以循环访问的变量。
目前,这就是我所拥有的。
$servers = Invoke-WebRequest -URI http://myserver/hostgroup.php?hostgroup=test | Select -expand Content
Run Code Online (Sandbox Code Playgroud)
这将返回一个简单的列表,例如"SERVER1","SERVER2","SERVER3",。我想循环浏览这个列表来运行报告。这是一个简单的 foreach 作为起点(不起作用)。
foreach ($s in $servers) {
if(Test-Connection -Quiet $s -Count 1) {
Write-Host "Online"
} else {
# connection test failed
Write-Host "`a`n" $s "is unreachable" -ForegroundColor Red
}
}
Run Code Online (Sandbox Code Playgroud)
我收到的输出看起来像是使用整个字符串作为服务器名称,并且没有分解它。
这是输出。
"SERVER1","SERVER2","SERVER3", is unreachable
Run Code Online (Sandbox Code Playgroud)