Function VerifyScript
{
$destination = "\\$server\c$\"
$script = "\\$server\C$\update.vbs"
$verify = test-path $script
If ($verify -match "False")
{
xcopy /C update.vbs $destination | out-null
Write-output "File copied to $server" >> "log.txt"
}
}
Function InstallUpdates
{
$wmiprocess = [wmiclass]"\\$server\root\cimv2:win32_process"
$wmiprocess.create("cscript.exe C:\update.vbs") | out-null
}
$servers = Get-Content "host.txt"
ForEach ($server in $servers)
{
VerifyScript
InstallUpdates
}
The script actually runs and does create the cscript process on the
remote machine, but disappears probably within 4 or 5 seconds and
nothing happens.
The update.vbs script is used to install all of the patches downloaded
from our WSUS server and then creates a log file on another folder
share.
It appears that while the script runs the cscript.exe command, it
ignores C:\update.vbs.
I've spent a week trying to research a good way to get this
accomplished but have had less than stellar luck finding anything
good. If anyone has any suggestions on what I could try, I would
greatly appreciate it.
Try:
$destination = "\\$server\c`$\"
$script = "\\$server\C`$\update.vbs"
--
Joel
"Joel Bennett" <Jay...@HuddledMasses.org> rakstija zinojuma
"news:eKFFpkxD...@TK2MSFTNGP03.phx.gbl"...
Function InstallUpdates {
[void]([wmiclass]"\\$server\root\cimv2:win32_process").Create("cscript.exe
C:\update.vbs")
}
Get-Content hosts.txt | %{VerifyScript; InstallUpdates}
in fact you can place all in one function:
filter Install-Update {
$server = $_
$destination = "\\$server\c$"
$script = Join-Path $destination "update.vbs"
if (!(test-path $script)) {copy update.vbs -destination $destination -ea 0
"File copied to $server" >> "log.txt"
}
[void]([wmiclass]"\\$server\root\cimv2:win32_process").Create("cscript.exe
C:\update.vbs")
}
and usage:
Get-Content hosts.txt | Install-Update
so, the error may be in your VBS file.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv
"proxb" <boe...@gmail.com> rakstija zinojuma
"news:6ac3d60b-5999-4cef...@k1g2000yqf.googlegroups.com"...
Thanks, I will give this a shot and see what happens. I still have a
lot to learn about powershell and appreciate all of the support in
helping to get this script off the ground and running.
I was able to verify that the vbscript works by running it on a couple
servers and had no issues with it prior to writing the powershell
script to run it remotely.
Just to be sure that it was something in the powershell script and not
the vbscript, i create a quick vbscript that would just create a text
file with a one line sentence on the c:\ of a server. I ran it locally
and it worked with no issues, however, once I ran it from the script,
it would kick off the cscript process but quit shortly after without
leaving a file.
I will use your recommendations for the script and will report back
the status.
Thanks again.
Don't write to c:\ only Admin's can write the file to c:\temp.
I also suspect you could issolate 99% or your problems more easily by
running the script under the scheduler on the local machine. Within your
script make certain you're not relying on either a current user's environment
or permissions. Lastly SMB will not work if this script is running under the
localsystem account and is not likely to work under either local service or
network accounts
"Boe" wrote:
> > "news:6ac3d60b-5999-4cef...@k1g2000yqf.googlegroups.com"....
Thanks Bob,
I had sent another message on here prior to your reply, but for some
reason, it failed to post. I am going to re-post the message and then
add my reply to you in it...
'No luck on this. Just to test it, I used my test.vbs script located
on the C:\ which just creates a text file with a one line sentence:
set ofso = CreateObject("Scripting.FileSystemObject")
set text = ofso.createtextfile("TEST.txt")
text.writeline "This is a test"
I was able to run it locally on the server using both wscript and
cscript. However when I try to run this line of code in powershell:
$server = "servername"
[void]([wmiclass]"\\$server\root\cimv2:win32_process").Create
("cscript.exe C:\test.vbs")
The only thing that happens is the command prompt windows opens for a
second and closes along with the cscript.exe process appearing in Task
Manager for a second or two and then disappearing.
It would appear that powershell doesn't want to read anything after
the cscript.exe portion of the script for some reason. '
Bob, this script is running under a Domain Administrator account that
has Administrator rights on all of the servers that this script will
be eventually hitting and eventually this powershell script will be a
scheduled task running from one server under a service account with
Domain Administrator rights. Are you talking about running the vbs
script as a scheduled task on the local server as opposed to running
the powershell script to kick off the vbscript? If so, I am trying to
avoid that as we have a lot of servers and this would be no better
than what we do already and our schedule for patching fluctuates to
greatly to set a schedule to run the install script.
Let me know if this makes sense and if not, I will clarify better as
sometimes when I write, I tend to say it for myself to understand
versus everyone else understanding...lol.
Also, I did some more searching and found a link that talks about
running the same command in vbscript:
http://blogs.technet.com/heyscriptingguy/archive/2007/10/29/hey-scripting-guy-how-can-i-start-a-remote-process-under-cscript-if-the-script-path-contains-blank-spaces.aspx
I am going to give this a try in vbscript form first and see if it
works, and if so, maybe see a way to convert this over to powershell,
if possible. Or if anything, call it from powershell with each server
to run against.
Thanks again.
Ok, I was successful in running the script I found to remotely run the
vbscript on the remote machine to create a text file. Here is the
script:
strComputer = "servername"
Set objProcess = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2:Win32_Process")
strCommand = "cscript " & Chr(34) & "C:\test.vbs" & Chr(34)
objProcess.Create strCommand,null,null,intProcessID
Now I am going to try to convert the 3rd line to powershell and give
it a go. If not, then I will call this script in powershell and try
to run it that way.
If I were you I'd hold off in changing a working script just to convert it
to a Powershell script. While I don't think the Powershell group achieved
their goal of working seemlessly with .BAT,VBS, native commands they have
done a good job.
When v2 ships remoting and jobs will be available to you which will make
executing remote calls easier. At that time you "may" find that by converting
to a Powershell script you can make you task easier.
In regards to the scheduler all I was trying to get at is this would have
independently verified that the script depended on
1) interactive desktop
2) current user environment Admin or not
3) current user permissions
4) interactive user. Processes launched via a service which I suspect WMI
must do at least in the remote case; will have troubles accessing anything
off box.
I will also take your advice on not converting the vbscript to
powershell, especially since I am very close to having this completed.
Thanks again everyone for helping me out with this.
On Jul 29, 12:53 pm, Bob Landau <BobLan...@discussions.microsoft.com>
wrote:
> > to run it that way.- Hide quoted text -
You _need_ to find out what context this script is running as.
Where does it get the patch? local machine or via the network? The latter
would explain volumes if it were not running under a user account.
The patches are downloaded from a WSUS server we have on the network.
I will post the contents of the script below:
'On Error Resume Next
CONST ForAppending = 8
CONST ForWriting = 2
CONST ForReading = 1
strlocalhost = "."
DestLog = "\\N15\C$\Documents and Settings\admin.prox\powershell\update
\PatchInstallLogs\"
Set oShell = CreateObject("WScript.Shell")
set ofso = createobject("scripting.filesystemobject")
Set updateSession = CreateObject("Microsoft.Update.Session")
Set updateSearcher = updateSession.CreateupdateSearcher()
Set updatesToInstall = CreateObject("Microsoft.Update.UpdateColl")
Set searchResult = updateSearcher.Search("IsInstalled=0 and
Type='Software'")
Set objWMI = GetObject("winmgmts:\\" & strlocalhost & "\root\CIMV2")
set colitems = objWMI.ExecQuery("SELECT Name FROM
Win32_ComputerSystem")
For Each objcol in colitems
'WScript.Echo "Name: " & objcol.Name
strcomputer = objcol.Name
Next
set objtextfile = ofso.createtextfile("C:\" & strcomputer &
"_patchlog.txt", True)
objtextfile.writeline "Creating collection of downloaded updates to
install:" & vbcrlf
For I = 0 To searchResult.Updates.Count-1
set update = searchResult.Updates.Item(I)
If update.IsDownloaded = true Then
objtextfile.writeline I + 1 & "> adding: " & update.Title
updatesToInstall.Add(update)
Else
objtextfile.writeline "No updates to install."
wscript.quit
End If
Next
err.clear
objtextfile.writeline vbcrlf & vbcrlf & "Installing updates..." &
vbcrlf
Set installer = updateSession.CreateUpdateInstaller()
installer.Updates = updatesToInstall
Set installationResult = installer.Install()
If err.number <> 0 Then
objtextfile.writeline "Error Occurred installing " & update.Title
objtextfile.writeline "Error: " & err.number
objtextfile.writeline "Descr: " & err.description
objtextfile.writeline vbcrlf
Else
'Output results of install
objtextfile.writeline "Installation Result: " &
installationResult.ResultCode
objtextfile.writeline "Reboot Required: " &
installationResult.RebootRequired & vbCRLF
objtextfile.writeline "Listing of updates installed " & "and
individual installation results:"
For I = 0 to updatesToInstall.Count - 1
objtextfile.writeline I + 1 & "> " & updatesToInstall.Item(i).Title
& ": " & installationResult.GetUpdateResult(i).ResultCode
Next
End If
ofso.copyfile strcomputer & "_patchlog.txt" , Destlog
ofso.deletefile strcomputer & "_patchlog.txt"
Wscript.Quit
One thing that I did find interesting was that if I use psexec.exe and
remotely start the script, it actually completes everything except for
the line where it should copy the file to another share. Here is the
command I used for psexec:
psexec -s -i \\$server cscript C:\update.vbs
-s = run as system on remote machine
-i = interact with desktop
If I just run the command as this:
psexec \\$server cscript C:\update.vbs
Then it fails with a permission denied at the following line in the
vbscript:
Set installer = updateSession.CreateUpdateInstaller()
On Jul 29, 10:19 pm, Bob Landau <BobLan...@discussions.microsoft.com>
> ...
>
> read more »- Hide quoted text -
WMI uses backslashes as escape characters, so you're right, that
should be "cscript.exe c:\\test.vbs".
While I do have this script working now, I will give that a shot just
to see what happens.
Thanks!
> > > > > > > > > The script actually runs and does create thecscriptprocess on the
> > > > > > > > > remote machine, but disappears probably within 4 or 5 seconds and
> > > > > > > > > nothing happens.
> > > > > > > > > The update.vbs script is used to install all of the patches downloaded
> > > > > > > > > from our WSUS server and then creates a log file on another folder
> > > > > > > > > share.
> > > > > > > > > It appears that while the script runs thecscript.exe command, it
> > > > > > > > > ignores C:\update.vbs.
>
> > > > > > > > > I've spent a week trying to research a good way to get this
> > > > > > > > > accomplished but have had less than stellar luck finding anything
> > > > > > > > > good. If anyone has any suggestions on what I could try, I would
> > > > > > > > > greatly appreciate it.- Hide quoted text -
>
> > > > > > > > - Show quoted text -
>
> > > > > > > Thanks, I will give this a shot and see what happens. I still have a
> > > > > > > lot to learn about powershell and appreciate all of the support in
> > > > > > > helping to get this script off the ground and running.
> > > > > > > I was able to verify that the vbscript works by running it on a couple
> > > > > > > servers and had no issues with it prior to writing the powershell
> > > > > > > script to run it remotely.
> > > > > > > Just to be sure that it was something in the powershell script and not
> > > > > > > the vbscript, i create a quick vbscript that would just create a text
> > > > > > > file with a one line sentence on the c:\ of a server. I ran it locally
> > > > > > > and it worked with no issues, however, once I ran it from the script,
> > > > > > > it would kick off thecscriptprocess but quit shortly after without
> > > > > > > leaving a file.
>
> > > > > > > I will use your recommendations for the script and will report back
> > > > > > > the status.
>
> > > > > > > Thanks again.- Hide quoted text -
>
> > > > > > - Show quoted text -
>
> > > > > Thanks Bob,
> > > > > I had sent another message on here prior to your reply, but for some
> > > > > reason, it failed to post. I am going to re-post the message and then
> > > > > add my reply to you in it...
>
> > > > > 'No luck on this. Just to test it, I used my test.vbs script located
> > > > > on the C:\ which just creates a text file with a one line sentence:
>
> > > > > set ofso = CreateObject("Scripting.FileSystemObject")
> > > > > set text = ofso.createtextfile("TEST.txt")
> > > > > text.writeline "This is a test"
>
> > > > > I was able to run it locally on the server using both wscript and
> > > > >cscript. However when I try to run this line of code in powershell:
>
> > > > > $server = "servername"
> > > > > [void]([wmiclass]"\\$server\root\cimv2:win32_process").Create
> > > > > ("cscript.exe C:\test.vbs")
>
> > > > > The only thing that happens is the command prompt windows opens for a
> > > > > second and closes along with thecscript.exe process appearing in Task
> > > > > Manager for a second or two and then disappearing.
> > > > > It would appear that powershell doesn't want to read anything after
> > > > > thecscript.exe portion of the script for some reason. '
> Thanks!- Hide quoted text -
"Boe" <boe...@gmail.com> rakstija zinojuma
"news:415bf4cb-9d1c-49e9...@t2g2000yqn.googlegroups.com"...
On Sep 10, 10:19 am, "Vadims Podans [MVP]" <vpodans> wrote:
> Do you want to only extract updates without installing them?
> --
> WBR, Vadims Podans
> MVP: PowerShell
> PowerShell blog -www.sysadmins.lv
>
> "Boe" <boep...@gmail.com> rakstija zinojuma
> ...
>
> read more »- Hide quoted text -