Asked by:
Export Powershel Results

General discussion
-
I'm trying to create a script that will tell me if a computer has a re-boot pending. I am running a cmd file that copies over the PowerShell file, runs then deletes said file.
if not exist \\%1\c$\. goto :err
copy /y %~dp0Get_Reboot.ps1 \\%1\C$\Sources
PsExec.exe \\%1 -s powershell -ExecutionPolicy Bypass -NonInteractive C:\Sources\Get_Reboot.ps1
del \\%1\C$\Sources\Get_Reboot.ps1The PowerShell script that I'm running;
# Install Install-Module -Name PendingReboot # Run Test-PendingReboot -Detailed
Returns the following information on screen;
ComputerName : 120706-YOGA370
ComponentBasedServicing : False
PendingComputerRenameDomainJoin : False
PendingFileRenameOperations : True
PendingFileRenameOperationsValue : {\??\C:\Program Files\Common Files\Microsoft Shared\ClickToRun\ApiClient.dll.bak, , \??\C:\Program Files\Common Files\MicrosoftShared\ClickToRun\OfficeClickToRun.exe.bak, ...}
SystemCenterConfigManager : False
WindowsUpdateAutoUpdate : False
IsRebootPending : TrueI have tried to run the script below but it formats the data in rows vs columns
Test-PendingReboot -Detailed | Select-Object ComputerName,ComponentBasedServicing,PendingComputerRenameDomainJoin,PendingFileRenameOpertions,PendingFileRenameOpertionsValue,SystemCenterConfigManager,WindowsUpdateAutoUpdate,IsRebootPending | Export-Csv c:\Logs\Reboot.csv
Is there a way to format it so it appears above (on screen)?
DHeinz
- Changed type Bill_Stewart Monday, July 29, 2019 8:24 PM
- Moved by Bill_Stewart Monday, July 29, 2019 8:24 PM Unanswerable drive-by question
Wednesday, April 17, 2019 6:58 PM
All replies
-
help format-Table -online
\_(ツ)_/
- Edited by jrv Wednesday, April 17, 2019 7:35 PM
Wednesday, April 17, 2019 7:35 PM -
If I use Out-File to a txt is displays the way I want it to but I would like to export as a csv.
DHeinz
Wednesday, April 17, 2019 8:05 PM -
If I use Out-File to a txt is displays the way I want it to but I would like to export as a csv.
DHeinz
Export-Csv will always be table format. A CSV can never be in list format.
\_(ツ)_/
- Edited by jrv Wednesday, April 17, 2019 8:28 PM
Wednesday, April 17, 2019 8:27 PM -
Does this give you the results you are looking for?
$rebootinfo=Test-PendingReboot -Detailed $rebootinfo >> C:\temp\outfile.csv
#the rest of the script is optional; include it only if you want a message box with the results. $userresponseend=[System.Windows.MessageBox]::Show("Reboot Info: $rebootinfo`n", 'Reboot Info','ok') if ($UserResponseend -eq "ok" ) { #Yes activity } else { exit }
I should point out that the ">>" on line two appends the output to the bottom of the .csv file each time the script runs; if you replace ">>" with ">" the output will overwrite the existing file. If you are looking for a new (additional) file to be generated each time the script runs you might want to add a line at the top:
$filename=Get-Date -format "dd-MM-yy HHmm"
and replace outfile.csv with $filename.csv
- Edited by skoomasteve Wednesday, April 17, 2019 9:29 PM
Wednesday, April 17, 2019 8:45 PM -
At present we are unable to run scripts on remote pc's. With that being said, I typically create a cmd file that launches a PSEXEC, copies the script over to the remote pc and then deletes it.
The script that I'm attempting to write creates a txt file with pending reboot data and deposits it to c:\Logs\. I am hving difficulty copying the resulting txt file back to the source computer from where the original files are launched from.
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force Install-Module -Name PendingReboot -Force Test-PendingReboot -Detailed | Select-Object ComputerName,ComponentBasedServicing,PendingComputerRenameDomainJoin,PendingFileRenameOpertions,PendingFileRenameOpertionsValue,SystemCenterConfigManager,WindowsUpdateAutoUpdate,IsRebootPending | Sort-Object ComputerNmae | Out-File c:\Logs\Reboot.txt Copy-Item -Credential - -Path c:\Logs\Reboot.txt -Destination \\#.#.#.#\P$\Remediation\CCM_SWUpdates\Logs\ -Recurse
DHeinz
- Edited by DRHeinz Thursday, April 18, 2019 5:06 PM
- Merged by Bill_Stewart Thursday, April 18, 2019 7:48 PM Duplicate
Thursday, April 18, 2019 5:01 PM -
Do not use "Recurse" with a single file. There is an extra "-" in your command line.
Copy-Item -Pathc:\Logs\Reboot.txt -Destination \\#.#.#.#\P$\Remediation\CCM_SWUpdates\Logs -Credential $cred
YOU must post the full error message.
\_(ツ)_/
Thursday, April 18, 2019 6:40 PM