Question

In: Computer Science

Windows PowerShell 1) Write a PowerShell Script to monitor a file for changes. 2) Write a...

Windows PowerShell

1) Write a PowerShell Script to monitor a file for changes.

2) Write a PowerShell Script to create a user account in a specific OU.

Solutions

Expert Solution

I HAVE ADDED BOTH THE SCRIPT PLEASE FIND THE CODE

ANSWER 1>

Function Register-Watcher {
param ($folder)
$filter = "*.*" #all files
$watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $false
EnableRaisingEvents = $true
}

$changeAction = [scriptblock]::Create('
# This is the code which will be executed every time a file change is detected
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file $name was $changeType at $timeStamp"
')

Register-ObjectEvent $Watcher -EventName "Changed" -Action $changeAction
}

Register-Watcher "c:\temp"

ANSWER 2>

Import-module activedirectory

#Import the list from the user
$Users = Import-Csv -Path C:\Users\vbedi\Desktop\Userlist.csv
foreach ($User in $Users)   
{ $Office
$Displayname = $User.Lastname + ", " + $User.Firstname   
$UserFirstname = $User.Firstname
$UserFirstIntial = $UserFirstname.Substring(1,1)
$Usermiddlename = $User.Middlename
$UserLastname = $User.Lastname   
$OU = $User.OU
$SAM = $User.SAM
$UPN = $UserFirstname.Substring(1,1) + $User.Lastname + "@" + $User.Maildomain   
$Description = $User.Description   
$Password = $User.Password

#Creation of the account with the requested formatting.
New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName $SAM -Office "Office" -UserPrincipalName $UPN -GivenName "$UserFirstname" -Surname "$UserLastname" -Description "$Description" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $True –PasswordNeverExpires $false -server server.domain.local   
$Displayname
}


Related Solutions

Write a Powershell script to create a Windows user account that is a non-admin user. This...
Write a Powershell script to create a Windows user account that is a non-admin user. This assignment assumes that you already have a Windows VM, with the administrator account created.. To complete the assignment, write the PowerShell script, run it on your VM, and submit the script here.
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script...
Write Powershell Script Verifies System Environment Variable Lmlicensefile Exists Exists S Q42980878 write a PowerShell script that verifies the 'System' environmentvariable, 'LM_LICENSE_FILE', exists. If it exists, the scriptshould also verify that the variable [email protected] (which represents the port and server theLM points to) as one of the values in the variable. Values (if anyare present) are separated by commas "," in this variable. Finally,if the value does not exist, this script should also performremediation (add the desired value to the...
1. Write a simple batch include IFELSE statments? 2. Write a simple Powershell Script with IFELSE...
1. Write a simple batch include IFELSE statments? 2. Write a simple Powershell Script with IFELSE statements? 3. Explain this powershell script and write its output? $x = 30 if($x -eq 10){ write-host("Value of X is 10") } elseif($x -eq 20){ write-host("Value of X is 20") } elseif($x -eq 30){ write-host("Value of X is 30") } else { write-host("This is else statement") }
Hi, Quick question regarding writing a Powershell script and creating a windows non-admin user account, is...
Hi, Quick question regarding writing a Powershell script and creating a windows non-admin user account, is this how you do it? Wanna know if I'm on the right track please and thanks! $Username = "AnnieSue" $Password = "78Annie" $group = "Users" $adsi = [ADSI]"WinNT://$env:COMPUTERNAME" $existing = $adsi.Children | where {$_.SchemaClassName -eq 'user' -and $_.Name -eq $Username } if ($existing -eq $null) {    Write-Host "Creating new local user $Username."    & NET USER $Username $Password /add /y /expires:never    Write-Host "Adding local user...
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import...
In PowerShell ISE create a script. Use the text file “its3410Users.txt” (found on Canvas) and import the users into your domain controller. The user file has a first name, last name, and department. Using this information, create users with the following specifications: Username will be first name.last name User Principal Name will be first name.last [email protected] The department signifies the OU that the user will be placed into If the department does not exist, create it Fill in the first...
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
1. How to create a group of users using a PowerShell script. 2. how to create...
1. How to create a group of users using a PowerShell script. 2. how to create a file consisting a group of 3 new user name’s and passwords, 1 to a line in power shell. 3. How to write a script in power shell to delete specific group of users. Prove that it works.
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: You are...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: You are going to create an HTML web page report from a standard processed report. You will use the text file “STUDENTS.TXT” located on Canvas. The script must meet the following requirements: The output file should be named ITS3410-{your name}.htm Every line of data that has a student number (9999-9999) must be included in the report All data must be trimmed No leading white space No...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions...
Using PowerShell ISE or VSCode, create a PowerShell script that will do the following: Create functions to get the following information Local username Local machine name Time zone Current Date Output the data that was collected to the screen Upload the script. Paste a screenshot of the results here
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT