这是一个获取一系列电脑上安装的所有打印机的脚本,我无法在不修改命令退出的情况下获取日志中的日期。 我想将日期放在退出命令的顶部/底部。
$fecha = (Get-Date).ToString(' dd.MM.yyyy "y en esta hora" HH:mm:ss')
$equipos = "D:\SCRIPTSM\despFi\cont-pla.txt"
$listaEquipos = Get-Content $equipos
foreach ($equipo in $listaEquipos){
Try {
if (test-connection -ComputerName $equipo -Count 1 -Quiet){
Get-Printer -ComputerName "$equipo" -ErrorAction Stop | Where-Object {$_.Name | Select-String -NotMatch "Fax","Microsoft","OneNote","PDF"} >> D:\SCRIPTSM\ALV\PRUEBA.log
}else{
Write-Output "El equipo $equipo está apagado el día $fecha " >> D:\SCRIPTSM\ALV\fallos.log
}
}catch{
$Error[0].Exception.Message
Write-Output "$equipo se necesita reiniciar para sacar las impresoras instaladas $fecha" >> D:\SCRIPTSM\ALV\PRUEBA.log
}
}
这就是我试图在里面获取日期的内容,但格式变得非常混乱。
$fecha = (Get-Date).ToString(' dd.MM.yyyy "y en esta hora" HH:mm:ss')
$equipos = "D:\SCRIPTSM\despFi\cont-pla.txt"
$listaEquipos = Get-Content $equipos
foreach ($equipo in $listaEquipos){
Try {
if (test-connection -ComputerName $equipo -Count 1 -Quiet){
$Impre = Get-Printer -ComputerName "$equipo" -ErrorAction Stop | Where-Object {$_.Name | Select-String -NotMatch "Fax","Microsoft","OneNote","PDF"}
Write-Output "$Impre Se realizó este día $fecha " >> D:\SCRIPTSM\ALV\PRUEBA.log
#Same code as on top continuing from here down
$fecha = (Get-Date).ToString(' dd.MM.yyyy "y en esta hora" HH:mm:ss')
$equipos = "D:\SCRIPTSM\despFi\cont-pla.txt"
$listaEquipos = Get-Content $equipos
foreach ($equipo in $listaEquipos){
Try {
if (test-connection -ComputerName $equipo -Count 1 -Quiet){
$Impre = Get-Printer -ComputerName "$equipo" -ErrorAction Stop | Where-Object {$_.Name | Select-String -NotMatch "Fax","Microsoft","OneNote","PDF"}
Write-Output $Impre $fecha >> D:\SCRIPTSM\ALV\PRUEBA.log
#Same code as on top continuing from here down