Link to home
Start Free TrialLog in
Avatar of Carl Billington
Carl BillingtonFlag for Australia

asked on

Help combine my PowerShell scripts

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;

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.
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Carl Billington


You are a genius!