Hi All,
I was preparing a script that can achieve three points about print spooler service. I have scripts for each of the items in the bullet point below, but I would like to combine all three steps into one script. Could some help to correct it please ? Thanks in advance !
• The script should verify the list of servers and provide the report, so I can identify which are holding printers/print server.
• Remaining servers, I need to stop and disable the spooler service
Final report of status of service.
Thanks again!
Shyam.
@syam.myinbox Welcome to PowerShell.org forums
Yes its possible, you can have a wrapper script which calls all three in a sequence or have code for all three scripts in one big script.
Have tried to make it in a single script ? are you getting any error ?
1 Like
Hi Kvprasoon,
Thank you for reaching out.
I just could prepare only these two script, not a single one. To be honest I am not sure, how to make it as a single one.
First one for finding all servers in the domain with print spooler service running.
Get-ADObject -Filter 'objectClass -eq "printQueue"' -Properties ShortServerName | Select-Object -ExpandProperty ShortServerName -Unique | Get-ADComputer | Format-Table | Out-File C:\temp\printers.csv
Second one for disabling the print spooler service and then verifying the current status with an output.
$servers=get-content -path "c:\temp\ServerList.txt"
foreach ($server in $servers) {
Set-Service -Name Spooler -Status Stopped -StartupType Disabled -Computername $server
Get-Service -Name Spooler -Computername $server | Select name,status,starttype | Out-File “C:\temp\PrinterStatus.csv”
}
Could you help me compile this into one please ?
Thanks a lot.
Shyam.
You are almost there. Are these two scripts or you execute copy pasting it to console ?
You don’t have any variables used, hence just copy past these two in a file and save it as a yourscriptname.ps1 and execute.
Note: Please try to format the code using the code formating option while posting. Its at the top for the posting editor.
tonyd
July 14, 2021, 2:53pm
7
Kvprasoon has a good point. It also looks like you will need to change:
Out-File C:\temp\printers.csv
To:
`Out-File C:\temp\printers.txt`
Then change:
$servers=get-content -path "c:\temp\ServerList.txt"
To:
$servers=get-content -path "c:\temp\printers.txt"
1 Like