November 9, 2015 at 3:52 pm
Hi All,
I have a requirement to kick off a Powershell script and pass a .txt file with it.
it works fine in Powershell ISE but I'm not able to run in from SQL Server.
Get-Content D:\Temp\ServerList.txt | D:\Temp\StopDisableWindowsUpdateService.ps1
November 9, 2015 at 3:59 pm
What is the error?
Shawn Melton
Twitter: @wsmelton
Blog: wsmelton.github.com
Github: wsmelton
November 9, 2015 at 4:46 pm
Shawn Melton (11/9/2015)
What is the error?
... and on which box is the "D:" drive?
--Jeff Moden
Change is inevitable... Change for the better is not.
November 10, 2015 at 1:15 am
Possibly permissions as usually it is running under different credentials.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
November 10, 2015 at 1:24 pm
I put the below command as a job step and made the step type as powershell.
Get-Content D:\Temp\ServerList.txt | D:\Temp\StopDisableWindowsUpdateService.ps1
Below is the Error I got.
Executed as user: REDMOND\bgitsdsv. A job step received an error at line 3 in a PowerShell script. The corresponding line is '$space.ForegroundColor = $host.ui.rawui.ForegroundColor'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Exception setting "ForegroundColor": "Cannot convert null to type "System.ConsoleColor" due to invalid enumeration values. Specify one of the following enumeration values and try again. The possible enumeration values are "Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, White"." '. Process Exit Code -1. The step failed.
November 10, 2015 at 1:43 pm
try piping the output of the .ps1 to a file or something.
November 10, 2015 at 2:05 pm
the powershell script is already writing the output to a .txt file. below is the script I'm trying to run.
BEGIN
{
Clear
}
PROCESS
{
$server = $_
set-service wuauserv -startuptype Disabled -computername $server -errorvariable errs 2>$null
$d = get-date
if ($errs.count -eq 0)
{
Write-output "$d :::::: SUCCEEDED :::::: $server :::::: The start type of service wuauserv has been set to Disabled" | out-file -append D:\Temp\StopDisableServiceLog.txt
}
else
{
Write-output "$d :::::: ERROR :::::: $server :::::: An error happened when trying to set the start type of service wuauserv to Disabled" | out-file -append D:\Temp\StopDisableServiceLog.txt
}
Invoke-command –computer $server –scriptblock {stop-service wuauserv} -errorvariable errs 2>$null
if ($errs.count -eq 0)
{
Write-output "$d :::::: SUCCEEDED :::::: $server :::::: The service wuauserv has been Stopped" | out-file -append D:\Temp\StopDisableServiceLog.txt
}
else
{
Write-output "$d :::::: ERROR :::::: $server :::::: An error happened when trying to stop the service wuauserv" | out-file -append D:\Temp\StopDisableServiceLog.txt
}
}
November 11, 2015 at 12:21 am
Sounds like you are trying to access properties that the host is not implementing. Understandably the UI free PowerShell host does not support a foreground colour.
Gaz
-- Stop your grinnin' and drop your linen...they're everywhere!!!
November 11, 2015 at 6:27 am
Why are you invoking a clear screen command in a script that should be pretty quiet and writing to a file?
November 11, 2015 at 1:51 pm
In this case how can i proceed. My requirement is below.
I'd like to stop and disable wuauserv service on servers which will be passed by a .txt file.
set-service wuauserv -startuptype Disabled -computername $serverName
Get-Service -Name SDOpsService -ComputerName $serverName | stop-service
November 11, 2015 at 1:57 pm
You're trying to disable windows update from a script running in sql?
November 11, 2015 at 2:00 pm
personally, if the answer to my previous is q is yes then i'd do something like:
1) export my server list that i keep in a handy sql table to a text file or csv
2) Pipe that text file into my .ps1
3) Schedule the export for (1) in SQL Agent
4) Schedule the .ps1 in Windows Scheduler on maybe your domain controller so it can hit all the servers/workstations on the network.
November 11, 2015 at 3:09 pm
Yes. I'd like to disable Windows Update Service using Powershell in SQL. If this succeeds, i have whole bunch of SQL jobs to schedule which would get kicked off only at customer approved time for server patching.
November 11, 2015 at 3:28 pm
Manic Star (11/11/2015)
You're trying to disable windows update from a script running in sql?
It has come to be a more common thing to do for some reason. I have seen other people have problems running this script from SQL Server.
Shawn Melton
Twitter: @wsmelton
Blog: wsmelton.github.com
Github: wsmelton
November 12, 2015 at 6:50 am
Wouldn't it be easier to work with a network admin to do a group policy instead?
Viewing 15 posts - 1 through 15 (of 17 total)
You must be logged in to reply to this topic. Login to reply