PowerShell Transcript log - PullRequest
       2

PowerShell Transcript log

0 голосов
/ 10 апреля 2019

Используя пакетный сценарий, я вызываю сценарий PowerShell на удаленном компьютере, поэтому здесь я вижу, что сценарий выполняется, но протокол стенограммы генерируется частично.Когда я запускаю вручную на локальном компьютере, журнал получает как ожидалось.Прилагается образец журнала.Код, который я использую, является простым служебным кодом.

Я вызываю скрипт PowerShell из командного файла с помощью команды

powershell -inputformat none C:\temp\cleanup.ps1

Вот код, который я использую

$VerbosePreference = "Continue"
$DaysToDelete = 2
$LogDate = get-date -format "MM-d-yy-HH"
$objShell = New-Object -ComObject Shell.Application 
$objFolder = $objShell.Namespace(0xA)
$ErrorActionPreference = "silentlycontinue"
#$MemoryDmpPath = "C:\Windows\Memory.dmp"
$MemoryDmp = $env:systemroot
$MemoryDmp


Start-Transcript -Path C:\Build\DiskClean-up.log
$After =  Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq "3" } | Select-Object SystemName,
@{ Name = "Drive" ; Expression = { ( $_.DeviceID ) } },
@{ Name = "Size (GB)" ; Expression = {"{0:N1}" -f( $_.Size / 1gb)}},
@{ Name = "FreeSpace (GB)" ; Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) } },
@{ Name = "PercentFree" ; Expression = {"{0:P1}" -f( $_.FreeSpace / $_.Size ) } } |
Format-Table -AutoSize | Out-String
$After

## Deletes the contents of the C:\Temp folder.
Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Explorer\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue |
Where-Object { ($_.LastWriteTIme -lt $(Get-Date).AddDays(-$DaysToDelete)) } 
#| remove-item -force -Verbose -recurse -ErrorAction SilentlyContinue
## The Contents of C:\Temp have been removed successfully!


## Deletes the contents of the C:\Temp folder.
Get-ChildItem "C:\Users\*\AppData\Local\Microsoft\Windows\Explorer\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue
#|remove-item -force -Verbose -recurse -ErrorAction SilentlyContinue
## The Contents of C:\Temp have been removed successfully!


## deletes the dmp files
$lastWrite =(Get-ItemProperty -Path $MemoryDmp\Memory.dmp -Name LastWriteTime).lastwritetime
$lastWrite

$timespan = new-timespan -days 30 -hours 00 -minutes 00

if (((get-date) - $lastWrite) -gt $timespan) {
    Write-host MEMORY.dmp file is older then 60 days hence delete.
    Remove-Item -path $MemoryDmp\MEMORY.DMP -force -Verbose
} else {
    Write-host MEMORY.dmp file is newer than 60 days and it cannot be deleted.
}

Stop-Transcript

Выходной журнал, который я ожидаю, будет выглядеть примерно так:

**********************
Windows PowerShell transcript start
Start time: 20190409151717
Username: home\admin1
RunAs User: home\admin1
Machine: home (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 9016
PSVersion: 5.1.14409.1018
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1018
BuildVersion: 10.0.14409.1018
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Temp\DiskClean-up.log
VERBOSE: Performing the operation "Stop-Service" on target "Windows Update (wuauserv)".
VERBOSE: Performing the operation "Remove Directory" on target "C:\Windows\Temp\BdeSqm".
VERBOSE: Performing the operation "Remove Directory" on target "C:\Windows\Temp\DPTF".
VERBOSE: Performing the operation "Remove File" on target "C:\Windows\Temp\DPTF\dptf_pnmwlanproxy.dll".
VERBOSE: Performing the operation "Remove File" on target "C:\Windows\Temp\DPTF\dptf_wwanproxy.dll".
VERBOSE: Performing the operation "Remove File" on target "C:\Windows\Temp\DPTF\dptf_pnmwlanproxy.dll".
VERBOSE: Performing the operation "Remove File" on target "C:\Windows\Temp\DPTF\dptf_wwanproxy.dll".
VERBOSE: Performing the operation "Remove Directory" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs\McTray_MC0X8CPC.log".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs\UpdaterUI_MC0X8CPC.log".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs\UpdaterUI_MC0X8CPC_error.log".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs\UpdaterUI_MC0X8CPC.log".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\McAfeeLogs\UpdaterUI_MC0X8CPC_error.log".
VERBOSE: Performing the operation "Remove Directory" on target "C:\users\A747231\AppData\Local\Temp\Outlook Logging".
VERBOSE: Performing the operation "Remove File" on target "C:\users\A747231\AppData\Local\Temp\Outlook Logging\Outlook-20190409T1112140152.etl".

**********************
Windows PowerShell transcript end
End time: 20190409151838
**********************

Но вывод, который я получаю, ниже

**********************
Windows PowerShell transcript start
Start time: 20190409151717
Username: home\admin1
RunAs User: home\admin1
Machine: home (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 9016
PSVersion: 5.1.14409.1018
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1018
BuildVersion: 10.0.14409.1018
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Temp\DiskClean-up.log
**********************
Windows PowerShell transcript end
End time: 20190409151838
**********************
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...