PowerShell; Date event triggers; File management

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ABCDEFGHI
Posts: 5
Last visit: Mon May 13, 2013 6:48 pm

PowerShell; Date event triggers; File management

Post by ABCDEFGHI »

Can anyone help with this Power Shell scripting? Here I attached my script.Would appreciate if I get some help.

Activity:

Perform all necessary Windows Updates prior to developing and executing the script.

Create a script called VeriVal.ps1 and save it wherever you like.
Be sure that the script is executable as a startup task as a result of logon. (Can be for a specific or All Users)

This script should do the following:

1.Acquire the user name. Do this either using a Cmdlet, the param() function or as a Read-Host call
2.In the current directory, look for a script called strtcln.ps1 in the root of the user's directory. If the file exists:
execute it
delete the script once it is finished
create a new file called secver.log (delete it if it exists already)
add the current date as a single-line string to the secver.log file
stop the execution of this script
3.Look for and read the first line of text of a file in the current directory called secver.log located in the root of the user's directory. Store the date information read from the file into a variable (it should only be a single line). If the file does not exist, ignore for now.
4.In the script, check the current date to see if it is within the first 7 days of the month. If not, then exit. If so, then check the date information read from the file. If the date information is also within the first 7 days of the current month (signifying that the script has already been executed for this month), then exit... otherwise continue.
5.If they are running either Vista or 7 (version numbers 5+), then ensure that they have the Security Center service started. If not, enable the service for automatic start and start the service.
6.Check to see if a user has the Windows Firewall and Windows Update services running. If not, enable the services to start automatically. Start the services.
7.Ask the user if performance optimizations are desired. If the user answers yes, inform the user that "the Superfetch service will be turned off. Superfetch optimizes PCs for long term performance and as such is designed for machines that are generally left on. PCs that are turned off at night do not benefit as much from it. Windows Search will also be turned off making search tasks on the desktop take a little longer. It does not affect web search via browsers. Do you want to continue?". If the user still selects yes, set both the Superfetch and Windows Search services to either Manual or Disabled.
8.Check to see if the user has Security Essentials installed. It should be installed by default in a folder called %ProgramFiles%\Microsoft Security Essentials. If Security Essentials is installed, set the Windows Defender service to be disabled.
9.You will now create a Powershell script containing a few commands to update the security status of your system. The executable used (MpCmdRun.exe) in the following steps will be located in your Defender or Security Essentials directory (whichever is installed).
e.g. "C:\Program Files\Windows Defender\MpCmdRun.exe" if Defender is active
e.g. "C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe" if Security Essentials is installed
create a script called strtcln.ps1 in the root of the users' directory
in this new script, make an entry to the Application Event Log using whatever descriptive text you need that you are invoking a signature update
add the following command as a single line of text to the script you just created "%installed directory%\MpCmdRun.exe -signatureupdate". Be sure the the correct installation directory is used
make another entry in the script to the Application Event Log using whatever descriptive text you need that you are invoking a security scan
add the following command as another single line of text to the script you just created "%installed directory%\MpCmdRun.exe -scan 0". Be sure the the correct installation directory is used
make an entry to the Application Event Log using whatever descriptive text you need that you updated the security status of the system
10.At this point, your VeriVal script is complete. Create a shortcut to the VeriVal script and place the shortcut in your Startup folder so that the script launches with each login. Remember to create your shortcut with Administrative privileges and to use the Powershell.exe executable as the target for your shortcut.
11.Test your script by executing it. You will need to change your system date via the Windows Task Bar to adequately test VeriVal. Be sure to test the script when:

current date is within the first 7 days of the month
current date is within the first 7 days of the month and secver.log has a date with a different month
current date is within the first 7 days of the month and secver.log has a date within the first 7 days of the current month
current date is within the first 7 days of the month and secver.log has a date outside of the first 7 days of the current month
on Windows XP (if possible)
on Vista/7 with only Defender installed
on Vista/7 with Security Essentials installed
the user desires optimizations to be performed
the user DOES NOT desire optimizations to be performed
the execution of strtcln.ps1 created manually outside of VeriVal
the execution of strtcln.ps1 as created by VeriVal
the whole process occurs where VeriVal is launched at login, creates strtcln.ps1, logoff, and log back in to see if strtcln.ps1 is launched and subsequently deleted after execution
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell; Date event triggers; File management

Post by jvierra »

You seem to have forgotten to attach your script.

You should also note an error messages that you are getting.
User avatar
galaara98
Posts: 10
Last visit: Tue Nov 08, 2016 10:59 am

Re: PowerShell; Date event triggers; File management

Post by galaara98 »

is this a school project... ;)
your code plan is very well defined, but you have no code... almost seems like you are asking someone to write a script to execute your plan?
User avatar
ABCDEFGHI
Posts: 5
Last visit: Mon May 13, 2013 6:48 pm

Re: PowerShell; Date event triggers; File management

Post by ABCDEFGHI »

galaara98 wrote:is this a school project... ;)
your code plan is very well defined, but you have no code... almost seems like you are asking someone to write a script to execute your plan?
Yes, school work. I dont have any anything done yet. sorry
User avatar
ABCDEFGHI
Posts: 5
Last visit: Mon May 13, 2013 6:48 pm

Re: PowerShell; Date event triggers; File management

Post by ABCDEFGHI »

jvierra wrote:You seem to have forgotten to attach your script.

You should also note an error messages that you are getting.
Havent done anything yet, sorry
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell; Date event triggers; File management

Post by jvierra »

You can get away with asking one specific question at a time but not how to solve the puzzle. The work is yours but we might help with some specific questions.
User avatar
ABCDEFGHI
Posts: 5
Last visit: Mon May 13, 2013 6:48 pm

Re: PowerShell; Date event triggers; File management

Post by ABCDEFGHI »

ABCDEFGHI wrote:
jvierra wrote:You seem to have forgotten to attach your script.

You should also note an error messages that you are getting.
Havent done anything yet, sorry
Here What I have so far..I know this not all and complete.
I really need this done, any help??


$username = Read-Host "Please enter your username"
$password = Read-Host -assecurestring "Please enter your password"
$scriptpath = Split-Path $MyInvocation.InvocationName
$file = 'H:\WindowsPowerShell\Extra\secver.log'
If (!(test-path $file))
{
New-Item $scriptpath\secver.log -ItemType file
}
If (test-path H:\WindowsPowerShell\Extra\strtcln.ps1)
{
$path = 'H:\WindowsPowerShell\Extra'
& "$path\strtcln.ps1" H:\WindowsPowerShell\Extra\ strtcln.ps1
Del $path\strtcln.ps1
If (test-path $file)
{del $file}
New-Item $file -itemtype file
$date = date
ac $file $date
Break
}
If
(test-path $file)
{
$line = (gc $file)
}
Write $line
User avatar
ABCDEFGHI
Posts: 5
Last visit: Mon May 13, 2013 6:48 pm

Re: PowerShell; Date event triggers; File management

Post by ABCDEFGHI »

ABCDEFGHI wrote:
galaara98 wrote:is this a school project... ;)
your code plan is very well defined, but you have no code... almost seems like you are asking someone to write a script to execute your plan?
Yes, school work. I dont have any anything done yet. sorry
Here What I have so far..I know this not all and complete.
I really need this done, any help??


$username = Read-Host "Please enter your username"
$password = Read-Host -assecurestring "Please enter your password"
$scriptpath = Split-Path $MyInvocation.InvocationName
$file = 'H:\WindowsPowerShell\Extra\secver.log'
If (!(test-path $file))
{
New-Item $scriptpath\secver.log -ItemType file
}
If (test-path H:\WindowsPowerShell\Extra\strtcln.ps1)
{
$path = 'H:\WindowsPowerShell\Extra'
& "$path\strtcln.ps1" H:\WindowsPowerShell\Extra\ strtcln.ps1
Del $path\strtcln.ps1
If (test-path $file)
{del $file}
New-Item $file -itemtype file
$date = date
ac $file $date
Break
}
If
(test-path $file)
{
$line = (gc $file)
}
Write $line


Any help for the rest of script or a bit more??
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: PowerShell; Date event triggers; File management

Post by jvierra »

That is not a specific question.

What is it that you are trying to do but cannot figure out. One thing not the whole project. We will not do your homework for you.
This topic is 10 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked