Asked by:
New Starters Script

Question
-
I need to add a log file to the end of this script that i have created
i am fairly new to Powershell and need some assistance
param(
[Parameter(Mandatory=$true)]$csvfile
)
Import-Module activedirectory
$users = Import-Csv -Path $csvfile
foreach ($user in $users)
{ #$Displayname = $user.lastname + "," + $user.Firstname
$GivenName = $user.Firstname
$Sn = $user.Lastname
$Name = "$($user.Lastname), $($user.Firstname)"
$SamAccountName = "$($user.Firstname).$($user.Lastname)"
$UserPrincipalName = $UserPrincipalName = $User.Firstname + "." + $User.Lastname + "" #Adds User Principle Name which was missing from previous script
$ProfilePath = $user.ou #user will be placed into the USERS ou on AD i will move them across manually
$Description = $user.Description
$password = $user.Password1
#creates new users
New-ADUser -DisplayName $Name -givenname "$GivenName" -Surname "$SN" -Name "$name" -SamAccountName "$samaccountname" -UserPrincipalName "$userprincipalname" -ProfilePath "$profilepath" -Description "$description" -Enabled $false
Add-ADGroupMember -identity Personal Folders and Desktop on Storm -Members $SamAccountName #adds the groups
Add-ADGroupMember -identity Internet User -Members $SamAccountName}
- Edited by Jon Gomes Tuesday, April 9, 2019 8:53 AM
- Moved by Bill_Stewart Monday, July 29, 2019 8:13 PM This is not "fix/debug/rewrite script for me" forum
Monday, April 8, 2019 3:29 PM
All replies
-
What is the issue? Why can't you add a log file? What do you mean by log file?
There is no log command in PowerShell. You will have to write code that outputs what you want to log.
Search for examples of writing to a file with PowerShell.
\_(ツ)_/
Monday, April 8, 2019 3:38 PM -
All you need to do is use Tee-Object to export data you want to text file and just add the -append
- Proposed as answer by ComputerScott Monday, April 8, 2019 10:30 PM
Monday, April 8, 2019 10:30 PM -
Sorry I didn't make myself clear.
I need to add a bit of code that will show the list of created users my script has created and it also has to have the date and time stamp
Tuesday, April 9, 2019 7:47 AM -
Sorry I didn't make myself clear.
I need to add a bit of code that will show the list of created users my script has created and it also has to have the date and time stamp
Tuesday, April 9, 2019 7:47 AM -
Sorry I didn't make myself clear.
I need to add a bit of code that will show the list of created users my script has created and it also has to have the date and time stamp
Please aske the person who wrote the script to modify it for you. We do not write scripts on request nor do we modify scripts you hve found for you.
Please carefully review the following links to set your expectation for posting in technical forums.
This Forum is for Scripting Questions Rather than script requests
Microsoft Virtual Academy - Getting Started with Microsoft PowerShell
\_(ツ)_/
Tuesday, April 9, 2019 9:06 AM -
im not asking if someone can do it for me I want to learn how to do it myself.
just need some assistance on where i can start
Tuesday, April 9, 2019 10:05 AM -
im not asking if someone can do it for me I want to learn how to do it myself.
just need some assistance on where i can start
The links I posted will teach you how to do this. You have to start at the beginning and learn the basics. There is no free lunch in PowerShell scripting.
\_(ツ)_/
Tuesday, April 9, 2019 10:24 AM