[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 668
  • Last Modified:

Running a script one time

I have a script that I need to run on all the machines on my network but I need to run it one time and one time only. What's the easiest way to do that?
0
Newsboy
Asked:
Newsboy
1 Solution
 
craskinCommented:
what does the script do? with some rewriting, it may not be necessary to worry about it running more than once.
0
 
oBdACommented:
Depends on what you're planning to do and what your network looks like.
If it's an AD domain, you have several possibilities:
* the logon script, running with user permissions
* a GPO with a user logon script, running with user permissions as well
* a GPO with a computer startup script, running with system permissions
Then there's Sysinternal's PsExec (http://www.sysinternals.com/Utilities/PsExec.html) that can be run against a list of machines.
Either way, you can just create a "flag file" in the script when the script has done its job, and if this flag file exists when the script starts, just exit.
0
 
Jandakel2Commented:
Most scripts can be edited to only run if they have not been ran before, i.e. if you are mapping a drive, check for the previously mapped drive and if it exists, halt the script process.  If you were to configure you script in this fashion, the easiest way to deploy it would be to set it up as part of your default domain policy, as either a computer startup script, or a user logon script.  I have an auditing program that I run, that I really only need ran once, but I leave it on for days at a time to make sure I get all the PC's and never see a detrimental impact....obviously all situations are different though...hope this helps,

JK
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Eagle6990Commented:
I second PSExec.  It work great and you can run it against either a list of machine, or the entire domain in one pass.
0
 
NewsboyAuthor Commented:
Here's the script

rem ******************************* FIXWSUS.CMD *************************************
net stop wuauserv

regsvr32 /s wuapi.dll

regsvr32 /s wups.dll

regsvr32 /s wuaueng.dll

regsvr32 /s wucltui.dll

regsvr32 /s msxml3.dll

c:
cd %windir%\SoftwareDistribution
rd /s/q DataStore
mkdir DataStore
rd /s/q Download
mkdir Download

net start wuauserv

rem Fixes problem with client machines not showing up on the server due to imaging method

reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v AccountDomainSid /f
reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v PingID /f
reg delete HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate /v SusClientId /f
cls
@echo Triggering detection after resetting WSUS client identity
net stop "Automatic Updates"
net start "Automatic Updates"
wuauclt /resetauthorization /detectnow
echo susid set to unique>c:\wsusfix.txt

exit

I like the flag idea, I am a domain with AD and use GP extensively. However I have little to no experience with actually writing script. So how would I edit this one to flag if it's been run or not?

Thanks so much I think this is what I'm looking for.
0
 
oBdACommented:
Looking at your script, you already have something that you can use for that:
echo susid set to unique>c:\wsusfix.txt

So all you need is a simple
if exist "c:\wsusfix.txt" goto :eof
at the beginning of the script.
0
 
NewsboyAuthor Commented:
Worked like a charm, thanks so much, I had not clue it was that easy. This will save me days of work.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now