Powershell,如何显示来自两个远程计算机连接的计划任务之间的差异结果?
我是一个使用Powershell的初学者,我需要一些帮助来解决这个问题。 我需要从两个不同的远程计算机连接获取计划任务的差异 首先,我使用compare object查找两个远程计算机连接中存在的任务之间的差异。代码如下:Powershell,如何显示来自两个远程计算机连接的计划任务之间的差异结果?,powershell,Powershell,我是一个使用Powershell的初学者,我需要一些帮助来解决这个问题。 我需要从两个不同的远程计算机连接获取计划任务的差异 首先,我使用compare object查找两个远程计算机连接中存在的任务之间的差异。代码如下: function get-taskdiff { [CmdletBinding()] Param ( # Param1 help description [Parameter(Mandatory=$true)]
function get-taskdiff
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true)]
[String]$ComputerName1,
# Param2 help description
[Parameter(Mandatory=$true)]
[String]$ComputerName2
)
$FirstComputerTaskName = invoke-command -computername $ComputerName1 {Get-ScheduledTask -taskpath "\" |select TaskName}
$SecondComputerTaskName = invoke-command -computername $ComputerName2 {Get-ScheduledTask -taskpath "\" |select TaskName}
Compare-object $FirstComputerTaskName.taskname $SecondComputerTaskName.taskname |
ForEach-Object {
if ($_.SideIndicator -eq '=>') {
$_.SideIndicator = "Not in $ComputerName1"
} elseif ($_.SideIndicator -eq '<=') {
$_.SideIndicator = "Not in $ComputerName2"
} elseif ($_.SideIndicator -eq '==') {
$_.SideIndicator = "Task exists in both $ComputerName1 and $ComputerName2"
}
$_
} |out-file C:\Users\mfg_dleebet\Documents\result.txt
}**
函数get taskdiff
{
[CmdletBinding()]
Param
(
#参数1帮助说明
[参数(必需=$true)]
[字符串]$ComputerName1,
#参数2帮助说明
[参数(必需=$true)]
[字符串]$ComputerName2
)
$FirstComputerTaskName=invoke命令-computername$ComputerName1{Get ScheduledTask-taskpath“\”|选择TaskName}
$SecondComputerTaskName=invoke命令-computername$ComputerName2{Get ScheduledTask-taskpath“\”|选择TaskName}
比较对象$FirstComputerTaskName.taskname$SecondComputerTaskName.taskname|
ForEach对象{
如果($侧指示器-等式'=>')){
$\ux.SideIndicator=“不在$ComputerName1中”
}elseif($侧指示器-等式'
function get-taskdiffv2
{
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Mandatory=$true)]
[String]$ComputerName1,
# Param2 help description
[Parameter(Mandatory=$true)]
[String]$ComputerName2
)
$FirstComputerTaskName = invoke-command -computername $ComputerName1 {Get-ScheduledTask -taskpath "\" }
$SecondComputerTaskName = invoke-command -computername $ComputerName2 {Get-ScheduledTask -taskpath "\" }
Compare-object $FirstComputerTaskName $SecondComputerTaskName -property taskname|
ForEach-Object {
if(($FirstComputerTaskName.taskname) -eq ($SecondComputerTaskName.taskname)){
if ($_.SideIndicator -eq '=>') {
$_.SideIndicator = "Task's state in $ComputerName1 is $FirstComputerTaskName.state"
} elseif ($_.SideIndicator -eq '<=') {
$_.SideIndicator = "Task's state in $ComputerName2 is $SecondComputerTaskName.state"
} elseif ($_.SideIndicator -eq '==') {
$_.SideIndicator = "Task's state in both $ComputerName1 and $ComputerName2 is $FirstComputerTaskName.state"
}
}
$_
} |out-file C:\Users\mfg_dleebet\Documents\result.txt
}