3/11/2023 0 Comments Powershell scripts for forensics![]() ![]() This is a guide to Useful PowerShell Scripts. To get expertise with scripts, it is advisable to write sample programs and practice them. Scripts can also be used to send emails or alerts to the user whenever an issue occurs. ![]() It also showed how a script can be run using a task scheduler. The advantage of the scripts is that they reduce human effort and the need for monitoring. Thus, the article covered various useful scripts that can be used to automate the tasks performed. In the action tab, specify the file location.In the trigger tab, set when this task needs to be run and the frequency of the job like whether it should be run daily or hourly and the time at which it needs to be run.Following are the steps to run a ps script via task scheduler The advantage with this approach is that there can’t be the risk of missing the running of the script and it saves the users time. ![]() That task will run the script at a specified time daily. The above script can be run daily without user intervention by creating a task. $ SMTPClientdet.Credentials = New-Object ($userdet, $passworddet) $SMTPClientdet = New-Object ($SMTPServerdet, 587) $SMTPMessagedet = New-Object ($EmailFromAdd,$EmailToAdd,$Subjectdet,$Bodydet) Import-Csv “C:\test\test.csv” | ForEach-Object ![]() The code is enclosed in a try-catch block to catch any exception if any error occurs it is printed on the console using the catch statement. The last line is used to add the user to an Active Directory group. The subsequent lines are used to assign the records values to the user’s attributes in the AD. The first line is used to import the csv document and loop through each record. After successful creation, a message will appear in the console saying that the user has been created in Active Directory. In case of an error, the script will log the error details in a text file. The CSV will have all the user-related properties that need the script to create a user in AD. The following script will add each user present in a CSV to the AD. The examples to be implemented in PowerShell Scripts are explained below: Example #1: Adding Users to AD Get-CimInstance -ClassName Win32_Service | Format-Table -Property Status,Name,DisplayName -AutoSize -WrapĮxamples to Implement in PowerShell Scripts Write-Host "Status of the running services are as follows" Get-CimInstance -ClassName Win32_ComputerSystem -Property UserName Write-Host "Current user logged in to the system" Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" |Measure-Object -Property FreeSpace,Size -Sum |Select-Object -Property Property,Sum Write-Host "The disk space details are as follows" ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |