5
Sto cercando di registrare i computer offline in un file di testo in modo che possa essere eseguito di nuovo in un secondo momento. Non sembra che sia stato registrato o catturato.Powershell try/catch con test-connection
function Get-ComputerNameChange {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
[string[]]$computername,
[string]$logfile = 'C:\PowerShell\offline.txt'
)
PROCESS {
Foreach($computer in $computername) {
$continue = $true
try { Test-Connection -computername $computer -Quiet -Count 1 -ErrorAction stop
} catch [System.Net.NetworkInformation.PingException]
{
$continue = $false
$computer | Out-File $logfile
}
}
if($continue){
Get-EventLog -LogName System -ComputerName $computer | Where-Object {$_.EventID -eq 6011} |
select machinename, Time, EventID, Message }}}
Sì che ha funzionato. Sapresti perché solo pipe nell'ultimo nome del computer nel mio file di testo? Sto cercando get-content "\\ test \ c $ \ powershell \ computers.txt" | get-computernameChange – MattMoo
@ user3620584 come fai a sapere che è solo il piping nell'ultima? – briantist
Come test inserisco 3 nomi di computer che non esistono e ne elenca solo l'ultimo nel file di registro. – MattMoo