Set IP address / mask / gateway / dns / domain
Windows 7:
-
Set IP to
192.168.<workstation>.2
-
Set gateway and DNS as Windows 2012 server.
-
Change domain to
network
after setting IP on Windows 2012
Windows 2012:
Get-NetAdapter | New-NetIPAddress -IPAddress 192.168.<computer_name>.1 -PrefixLength 24
Import-Module ActiveDirectory
Create Organisational unit
New-ADOrganizationalUnit -Name <ouName> -Path "dc=network,dc=local
Create groups
New group (Three groups)
New-ADGroup -name <groupname> -groupscope Global -Path "ou=<ouName>,dc=network,dc=local"
Create users
Remember to put spaces before the backtick (button above tab)
First file
$batch = Import-csv '.\Documents\file1.csv'
foreach ($user in $batch){
New-ADuser -Path "ou=unit,dc=network,dc=local" `
-UserPrincipalName $user.UPN `
-Name $user.Name `
-AccountPassword (ConvertTo-SecureString -AsPlainText $user.Password -Force) `
-GivenName $user.FirstName `
-Surname $user.Surname `
-Enabled 1
if([INT]$user.groupID -eq 8){
Add-ADGroupMember -Identity <groupname> -Members $user.Name
} elseif ([INT]$user.groupID -eq 7){
Add-ADGroupMember -Identity <groupname> -Members $user.Name
}
}
Second file
$batch = Import-csv '.\Documents\file2.csv'
foreach ($user in $batch){
New-ADuser -Path "ou=unit,dc=network,dc=local" `
-UserPrincipalName $user.UPN `
-Name $user.Name `
-AccountPassword (ConvertTo-SecureString -AsPlainText $user.Password -Force) `
-GivenName $user.FirstName `
-Surname $user.Surname `
-LogonWorkstations $user.Name `
-Enabled 1
Add-ADGroupMember -Identity <groupname> -Members $user.Name
}
Script to REMOVE users in case of mistake DON'T USE UNLESS NEEDED
$batch = Import-csv '.\Documents\file2.csv'
foreach ($user in $batch){
Remove-ADUser -Identity $user.Name -Confirm:$false
}
Create SMB Shares (Shared folders)
- Make a folder using the GUI
- Create SMB Share (The -Name is what is shown to the clients)
New-SMBShare -Name <smbname> -Path <PathToFolder> -FullAccess/NoAccess/ReadAcess <members>
Change access right of Shares
Grant Access to a share:
Grant-SmbShareAccess -name <smbname> -AccessRight <read/write/full> -AccountName <username>
Deny Access to a share:
Block-SmbShareAccess -Name <smbname> -AccountName <username>
Miscellaneous
View members of a group
Get-ADGroupMember -Identity <groupname>
Make files using PowerShell
new-item -path . -name <file.extension> -itemtype "file"
Launch ISE and run script
ise <filename>
& ./<filename>
Policy
Get-ExecutionPolicy
Set-ExecutionPolicy -ExecutionPolicy <Unrestricted>
Alias
New-Alias -Name <aliasname> -Values <command/path to script>
Comparison operators
-eq Equal
-ne Not equal
-ge Greater than or equal
-gt Greater than
-lt Less than