Sunteți pe pagina 1din 18

Network Scripting - Learning Activities

ICTNWK409
Create scripts for networking

Class Learning Activities

Document1 Last revised 13 February 2020 Page 1 of 18


Network Scripting - Learning Activities

INTRODUCTION TO SCRIPTING
Accessing Command Line
Access to the command line can be from the run window by typing “cmd” or accessing the
command prompt from the start menu.

Getting Help
Whilst in the command window type the word “help” this will display a list of available commands

Querying switches for commands


To identify further parameters of a command, enter the command followed by “/?”

Running a command and displaying output


After running a command the output will normally display to the computer screen

Redirecting output to a file (use of >)


The output of a command can be redirected to specific file by using the “>” symbol followed by
the name of the file. If the “>” is used a second time to the same file then the content will be
overwritten.

Appending output to an existing file (use of >>)


To redirect the output of multiple commands to the same file then a “>>” will be required to
append additional content.

Document1 Last revised 13 February 2020 Page 2 of 18


Network Scripting - Learning Activities

LOCAL COMPUTER FOLDERS AND


DIRECTORIES
Creating a directory
The following command “md” or “mkdir” (make directory) is used to create a directory or folder
the example below is creating the student directory or folder on the root of C: drive.
md c:\student

Creating a subdirectory
The following command “md” or “mkdir” (make directory) is used to create a sub-directory or
sub-folder the example below is creating the documents directory or folder as a sub directory of
the student directory or folder on the root of C: drive.
md c:\student\documents

Directory listing
The following command “dir” is used to provide a directory listing of the existing directories or
folders, the output will be displayed on the computer screen.
dir c:\student

Removing a directory
The following command “rd” or “rmdir” (remove directory) is used to delete a directory or folder
the example below is deleting the student directory or folder on the root of C: drive.
rd c:\student

Document1 Last revised 13 February 2020 Page 3 of 18


Network Scripting - Learning Activities

DISCOVER LOCAL COMPUTER SYSTEM


INFORMATION
Discover the local physical network adapter address
get mac

Discover the local physical computer name


hostname

Discover all system hardware / software information


systeminfo

Document1 Last revised 13 February 2020 Page 4 of 18


Network Scripting - Learning Activities

CREATING, COPYING AND MOVING FILES


Creating a file with a string of text
echo “scripting repetitive tasks is time saving“ > c:\script.txt

To copy a file between locations


copy source destination

Example:
copy c:/movies/logan.mkv d:/mymovies/logan.mkv
(this command copies a single file from the movies folder to the subfolder of
xmen with the movies folder leaving the original file in place)

To move a file between locations


move source destination

Example: move c:/movies/logan.mkv c:/movies/xmen/logan.mkv


(this command moves a single file from the movies folder to the subfolder of
xmen with the movies folder)

Example: move c:/movies/*.mkv c:/movies/xmen/*.mkv


(this command moves a all files with an extension of .mkv from the movies folder
to the subfolder of xmen with the movies folder)

Document1 Last revised 13 February 2020 Page 5 of 18


Network Scripting - Learning Activities

LOCAL COMPUTER USER AND GROUP


ACCOUNTS
Creating a user account to local computer
net user username password /ADD

Example: net user todd P@55word /ADD


(This command will create the user account of todd and assign the password to user account)

Creating a user account to local computer (prompt for password)


net user /add username *

Example: net user /add todd *


(This command will create the user account of todd and prompt you the administrator for
a password to be assigned to the user account, the password will be masked and not visible to
passersby)

Deactivate a user account


net user username /active:no

Example: net user todd /active:no


(This command will deactivate the user account)

reactivate a user account


net user username /active:yes

Example: net user todd /active:yes


(This command will reactivate the user account)

Document1 Last revised 13 February 2020 Page 6 of 18


Network Scripting - Learning Activities

Set Time Limits (restrictions) for a Regular Account in Windows 10

net user <username> /time:<day>,<time>


 Replace <username> with the name of the user account you want to limit.
 Replace <day> with the day you want to set limits on. You can spell out the full names of
the days or use the initials Su, M, T, W, Th, F, Sa.
 Replace <time> with a time range using either a 12-hour (3am, 1pm, etc.) or 24-hour
(03:00, 13:00, etc.) format. You can only use times in one-hour increments, so don’t add
any minutes to the times.

net user simon /time:Sa,8am-4pm


or
net user simon /time:M-F,4pm-8pm
or
net user simon /time:Sa,8am-4pm;M-F,4pm-8pm

Deleting a user account from the local computer


net user username /delete

Example: net user todd /delete


(This command will reactivate the user account)

Creating a local group account to local computer


net localgroup group_name /add

Example: net localgroup cert4students /add


(This command will create an group account)

Document1 Last revised 13 February 2020 Page 7 of 18


Network Scripting - Learning Activities

Adding a local user to a group account on a local computer


net localgroup group_name UserLoginName /add

Example: net localgroup cert4students todd /add

Deleting a local group account from the local computer


net localgroup group_name /delete

Example: net localgroup cert4students /delete

Document1 Last revised 13 February 2020 Page 8 of 18


Network Scripting - Learning Activities

LOCAL COMPUTER NAMES/ACCOUNTS


Renaming a server/computer
netdom renamecomputer currentname /newname:newservername

Example:
netdom renamecomputer randomename /newname:server

Appending server name information and setting Primary DNS suffix

Example:
netdom computername server /add: server.lidcombe-it.local
netdom computername server /MakePrimary server.lidcombe-it.local

Document1 Last revised 13 February 2020 Page 9 of 18


Network Scripting - Learning Activities

ASSIGNING NETWORK ADDRESSING TO


LOCAL COMPUTER SYSTEM

Setting dynamic IP address from command line


netsh interface ip set address name=”Ethernet” source=dhcp

Setting static IP address from command line


netsh interface ip set address name=”Ethernet” static hostdevice_IP Subnetmask GW_IP
netsh interface ip set address name=”Ethernet” static 192.168.0.1 255.255.255.0 192.168.0.254

Changing DNS Setting (primary dns)


netsh interface ip set dns name=”Local Area Connection” static 192.168.0.250

Changing DNS Setting (secondary dns)


netsh interface ip add dns name=”Local Area Connection” 8.8.8.8 index=2

Document1 Last revised 13 February 2020 Page 10 of 18


Network Scripting - Learning Activities

SHARING LOCAL COMPUTER RESOURCES

Sharing folders on the local computer/server and sharing permissions


net share sharename=drive:path /grant:user,permission
net share mymovies=k:\movies /grant:tony,read

Sharing folders on the local computer and sharing permissions (multiple users/groups)
net share mymovies=c:\movies /grant:group1,read /grant:group2,change

Removing a shared folder


net share sharefolder /delete
net share mymovies /delete

Mapping shared folders as network drives


net use drive: \\computername or ipaddress\sharename
net use z: \\Teacher104\testshare
net use z: \\192.168.104.196\testshare

net use z: \\server\org_data

Document1 Last revised 13 February 2020 Page 11 of 18


Network Scripting - Learning Activities

POWERSHELL COMMANDS

Rename the local computer


Rename-Computer -NewName "Server-A" -Restart

Change IP Address
New-NetIPAddress –InterfaceAlias “Wired Ethernet Connection” –IPv4Address “192.168.0.1”
–PrefixLength 24 -DefaultGateway 192.168.0.254

Setting Your DNS Information


Set-DnsClientServerAddress -InterfaceAlias “Wired Ethernet Connection” -ServerAddresses
192.168.0.250

Check what role and features are installed


get-windowsfeature

Install the role of DNS using PowerShell


Install-WindowsFeature DNS –IncludeManagementTools

Create a primary zone (Forward lookup)

Add-DnsServerPrimaryZone -Name "lidcombe-it.local" -ZoneFile " lidcombe-it.dns"

-DynamicUpdate "NonsecureAndSecure"

Document1 Last revised 13 February 2020 Page 12 of 18


Network Scripting - Learning Activities

Create a host record for server


Add-DnsServerResourceRecordA -Name 'servername' -ZoneName 'lidcombe-it.local' -IPv4Address
192.168.15.10

Create a primary zone (Reverse lookup)

Add-DnsServerPrimaryZone -NetworkID "192.168.15.0/24" -ZoneFile " "15.168.192.in-


addr.arpa.dns" -DynamicUpdate "NonsecureAndSecure"

Installing the Active Directory Domain Service


install-windowsfeature AD-Domain-Services

Installing the First Domain Controller in Forest


Install-ADDSForest
-CreateDnsDelegation:$false
-DatabasePath “C:\Windows\NTDS”
-DomainMode “Win2016”
-DomainName “lidcombe-it.local”
-DomainNetbiosName “lidcombe-it”
-ForestMode “Win2016”
-InstallDns:$true
-LogPath “C:\Windows\NTDS”
-NoRebootOnCompletion:$false
-SysvolPath “C:\Windows\SYSVOL”
-Force:$true

Document1 Last revised 13 February 2020 Page 13 of 18


Network Scripting - Learning Activities

Install Active Directory Users and Computers using Powershell


Import-Module ServerManager
Add-WindowsFeature RSAT-ADDS-Tools

Document1 Last revised 13 February 2020 Page 14 of 18


Network Scripting - Learning Activities

CREATING ACTIVE DIRECTORY OBJECTS


(From the domain controller - server)

Adding Organisational Unit object to Active Directory


dsadd ou “ou=finance, dc=lidcombe-it, dc=local”

Adding group account object to Active Directory


dsadd group “cn=finance users, ou=finance, dc=lidcombe-it, dc=local” –secgrp yes –scope g

Adding a user account object to Active Directory


dsadd user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” –samid bgates –fn Bill –ln Gates –
pwd P@55word

Adding a user account object to Active Directory with group membership


dsadd user “cn=TCook, ou=finance, dc=lidcombe-it, dc=local” –samid tcook
–fn Tim –ln Cook –pwd P@55word –memberof “cn=finance managers, ou=finance,
dc=lidcombe-it, dc=local”

Adding a user account object to Active Directory with multiple group memberships
dsadd user “cn=LTorvalds, ou=finance, dc=lidcombe-it, dc=local” –samid ltorvalds –fn Linus –ln
Torvalds –pwd P@55word –memberof “cn=finance users, ou=finance, dc=lidcombe-it, dc=local”
“cn=finance managers, ou=finance, dc=lidcombe-it, dc=local”

Document1 Last revised 13 February 2020 Page 15 of 18


Network Scripting - Learning Activities

MODIFYING ACTIVE DIRECTORY OBJECTS


(organisational units, user and group accounts)

Disabling a user account


dsmod user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” –disabled yes

Disabling multiple user account


dsmod user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” “cn=TCook, ou=finance,
dc=lidcombe-it, dc=local” –disabled yes

Resetting a user account password


dsmod user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” –pwd Passw0rd! –mustchpwd yes

Resetting multiple user account password


dsmod user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” “cn=TCook, ou=finance,
dc=lidcombe-it, dc=local” –pwd Passw0rd! –mustchpwd yes

Adding new members to existing group


dsmod group “cn=infotech users, ou=finance, dc=lidcombe-it, dc=local” –addmbr “cn=TCook,
ou=finance, dc=lidcombe-it, dc=local”

List of users from a specific organisational unit


dsquery user “ou=finance, dc=lidcombe-it, dc=local”

List of groups a user belongs too.


dsget user “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” –memberof –expand

Document1 Last revised 13 February 2020 Page 16 of 18


Network Scripting - Learning Activities

MOVING ACTIVE DIRECTORY OBJECTS


(organisational units, user and group accounts)

Moving a user account between OU’s


dsmove “cn=BGates, ou=finance, dc=lidcombe-it, dc=local” –newparent “ou=sales, dc=lidcombe-it,
dc=local”

Rename a user account


dsmove “cn=TCook, ou=finance, dc=lidcombe-it, dc=local” –newname “T Andrews “

Document1 Last revised 13 February 2020 Page 17 of 18


Network Scripting - Learning Activities
Creating users with powershell
New-ADUser -SamAccountName "glenjohn" -GivenName "Glen" -Surname "John" -DisplayName
"Glen John" -Path 'OU=Finance,DC=fabrikam,DC=local' -AccountPassword P@55word

Document1 Last revised 13 February 2020 Page 18 of 18

S-ar putea să vă placă și