430 w8 Benchmark - Security Automation With PowerShell

Riri01
ITT-430Benchmark-SecurityAutomationwithPowerShellCREATINGAPOWERSHELLSCRIPT.docx

ITT-430 Benchmark - Security Automation with PowerShell

Creating a PowerShell Script

In this exercise, you will create script by declaring parameters (like declaring variables in programming) and using the Copy-Item cmdlet.

· For param use: review https://technet.microsoft.com/en-us/library/jj554301.aspx

· For Copy-Item use: review https://technet.microsoft.com/en-us/library/ee156818.aspx

In your Windows Server, place the following contents into a text file (or use MS PowerShell IDE) to create and save the script as ITT430Copy.ps1 file. Save it and note the location.

param(

[string]$computerName,

[string]$filePath

)

Copy-Item -Path $computerName -Destination $filePath -Recurse

Creating a Scheduled Task to Automate the Script

In Windows Server, open MS PowerShell IDE

Perform the following commands:

Define the Scheduled Task

$Action = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument “-NonInteractive -NoLogo -NoProfile -File C:\ ITT430Copy.ps1 -SourcePath C:\ITT430-Files* -DestinationPath \\ITT430-SV1\ITT430-Storage"

Set Schedule Trigger (time to execute)

$Trigger = New-ScheduledTaskTrigger -Once -At '12AM' -RepetitionInterval (New-TimeSpan -minutes 15) -RepetitionDuration (New-Timespan -hour 1000)

Place Scheduled Task and Trigger into memory

$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings (New-ScheduledTaskSettingsSet)

Register the Scheduled Task into System Scheduler

$Task | Register-ScheduledTask -TaskName 'File Transfer AutoSync' -User 'DomainAdmin' -Password 'password'

$Task

© 2020 Grand Canyon University. All Rights Reserved.