We help IT Professionals succeed at work.
Get Started

Help combine my PowerShell scripts

Carl Billington
Last Modified: 2015-10-15
Can someone please help me combine multiple PowerShell scripts below. I will detail each step exactly what I action manually.

1. I run; C:\Scripts\Pending Reboots\ServersExport.ps1
import-module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1' -force
cd AVA:
$Members = Get-CMDevice -CollectionName "All Servers"
$Members | select Name | Out-File "C:\Scripts\Pending Reboots\All Servers.txt"

Open in new window

2. I run; C:\Scripts\Pending Reboots\WhiteSpaces.ps1
$content = Get-Content 'C:\Scripts\Pending Reboots\All Servers.txt'
$content | Foreach {$_.TrimEnd()} | Set-Content 'C:\Scripts\Pending Reboots\All Servers.txt'
Get-Content 'C:\Scripts\Pending Reboots\All Servers.txt' | Where-Object {$_ -notmatch 'Name'} | Set-Content 'C:\Scripts\Pending Reboots\All Servers1.txt'
Get-Content 'C:\Scripts\Pending Reboots\All Servers1.txt' | Where-Object {$_ -notmatch '----'} | Set-Content 'C:\Scripts\Pending Reboots\All Servers.txt'
remove-item -path 'C:\Scripts\Pending Reboots\All Servers1.txt' -force

Open in new window

3. I run this command: . .\Get-PendingReboot.ps1
As per; https://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542

4. I run; C:\Scripts\Pending Reboots\PendingRebootReport.ps1
$Servers = Get-Content 'C:\Scripts\Pending Reboots\All Servers.txt' 
Get-PendingReboot -Computer $Servers | Export-Csv 'C:\Scripts\Pending Reboots\PendingRebootReport.csv' -NoTypeInformation

Open in new window

Thank you.
Watch Question
PowerShell Developer
Top Expert 2010
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE