Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- #
- #
- param ($computer)
- if ($computer -eq $null) {
- $computer = read-host -Prompt "Please enter a computer name (e.g.: bgc-kevin, bgc-mike, bgc-dean,...)"
- }
- function cleanup-remote {
- param ($RemovableFiles)
- ForEach ($RemovableFile in $RemovableFiles) {
- $retval = Invoke-Command -Session $rs -ScriptBlock {
- Param($RemovableFile)
- Try {
- Remove-Item -LiteralPath $RemovableFile -ErrorAction Stop
- return "Removed $RemovableFile"
- }
- Catch {
- return $_
- }
- } -ArgumentList $RemovableFile
- # note, $retval now has any output from the try/catch block
- Write-Host "<d> $computer - $retval"
- } # ForEach
- }
- #
- # Define paths
- #
- $LogFileSource = "C:\Windows\Logs\WindowsUpdate\WinSxS-stats.txt"
- $LogFileTarget = "C:\Users\administrator.CORP\stats-$computer.txt"
- $PayloadSource = "C:\Users\administrator.CORP\code\collect-sxs-info.ps1"
- $PayloadTarget = "C:\Users\Administrator\collect-sxs-info.ps1"
- $DuFileSource = "C:\Users\administrator.CORP\code\du64.exe"
- $DuFileTarget = "C:\Users\Administrator\du64.exe"
- [string[]]$RemovableFiles = $LogFileSource, $PayloadTarget, $DuFileTarget
- #
- # Connect
- #
- $rs = New-PSSession $computer
- Write-Host "<o> $computer - Opened connection $rs"
- Cleanup-Remote($RemovableFiles)
- #
- # Drop files
- #
- Copy-Item -ToSession $rs $PayloadSource -Destination $PayloadTarget
- Write-Host "--> $computer - Delivered $PayloadTarget"
- Copy-Item -ToSession $rs $DuFileSource -Destination $DuFileTarget
- Write-Host "--> $computer - Delivered $DuFileTarget"
- #
- # Run
- #
- Write-Host -nonewline "<-> $computer - Running collect-sxs-info.ps1... "
- Invoke-Command -Session $rs -ScriptBlock { C:\Users\Administrator\collect-sxs-info.ps1 }
- Write-Host "Done"
- #
- # Check data
- #
- # Invoke-Command -Session $rs -ScriptBlock { Param($path); Get-ChildItem -Path $path } -ArgumentList $LogFileSource
- #
- Copy-Item -FromSession $rs $LogFileSource -Destination $LogFileTarget
- Write-Host "<-- $computer - Received $LogFileTarget"
- #
- # Cleanup
- #
- Cleanup-Remote($RemovableFiles)
- Remove-PSSession -session $rs
- write-host "<c> $computer - Closed connection $rs"
Add Comment
Please, Sign In to add comment