$ScheduledTaskName = '<Task Name>'
$TargetMachine = '<Target Machine>'
$SSHUsername = '<SSH Username>'
$ScheduledTaskStatus = Invoke-Command `
-HostName $TargetMachine `
-UserName $SSHUsername `
-ScriptBlock { `
Stop-ScheduledTask -TaskName $Using:ScheduledTaskName; `
Set-ScheduledTask -TaskName $Using:ScheduledTaskName -User $Using:Params.user -Password $Using:Params.newPassword; `
Start-ScheduledTask -TaskName $Using:ScheduledTaskName; `
return Get-ScheduledTask $Using:ScheduledTaskName | Select-Object -ExpandProperty "State";
}
Write-Debug "$ScheduledTaskName is: $($ScheduledTaskStatus.State)"
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline=$true)]
[string]
$Record
)
# ユーザー定義パラメータ
$ErrorActionPreference = "Stop"
$DebugPreference = 'Continue'
$ScheduledTaskName = '<Task Name>'
$TargetMachine = '<Target Machine>'
$SSHUsername = '<SSH Username>'
$RecordJsonAsB64 = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($Record))
$Params = ($RecordJsonAsB64 | ConvertFrom-Json -ErrorAction Stop)
Write-Debug "Running Post-Rotation Script on = $($Params.userRecordUid)"
$ScheduledTaskStatus = Invoke-Command `
-HostName $TargetMachine `
-UserName $SSHUsername `
-ScriptBlock { `
Stop-ScheduledTask -TaskName $Using:ScheduledTaskName; `
Set-ScheduledTask -TaskName $Using:ScheduledTaskName -User $Using:Params.user -Password $Using:Params.newPassword; `
Start-ScheduledTask -TaskName $Using:ScheduledTaskName; `
return Get-ScheduledTask $Using:ScheduledTaskName | Select-Object -ExpandProperty "State";
}
Write-Debug "$ScheduledTaskName is: $($ScheduledTaskStatus.State)"