EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PowerShell Administrator

By Priya PedamkarPriya Pedamkar

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » PowerShell Administrator

PowerShell Administrator

Introduction to PowerShell Administrator

PowerShell administrator is a person who is responsible for maintaining the overall windows-based servers of an organization. They are also responsible for maintaining the integrity of the data of the organization. They also play a pivotal role in maintaining the on-boarding and off-boarding of employees as they are the ones responsible for maintaining the active directory of the organization. PowerShell administrators are also known as windows administrators.

Different ways of Running as PowerShell Administrator

There is a major difference between running a cmdlet or a script in PowerShell in a normal mode from that of an administrator mode. It is because most of the operations require admin access and only a PowerShell administrator has the privilege to perform those operations.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

The following are the different ways in which PowerShell can be run in admin mode:

  • Search for PowerShell and right-click and select run as administrator.
  • Open PowerShell using the run command. Once the PowerShell window is opened, type as Start-Process PowerShell -verb run as and press the enter key.
  • By using task manager, create a new task. In the name, type PowerShell and check the “Create this task with administrative privileges” and press enter.

Roles and Responsibilities of PowerShell Administrator

Given below are the roles and responsibilities :

1. Check for patches

One of the main responsibilities of a PowerShell administrator is to check for the latest patches that are available and install them. This is a crucial part for any organization to prevent the resources from vulnerabilities attacks and other security related issues. Most of the organization’s patches are installed on a monthly basis to avoid any threats. Get-Hotfix cmdlet is used to find the patches. If we know the id of the patch, then that KB article value should be passed.

Example:

Code:

Get-Hotfix

Output:

It will display the list of all patches that are installed in the local computer.

PowerShell Administrator 1

2. Monitoring the disk space availability

The other important task of the PowerShell administrator is to monitor the available disk space in the system. This process will be tedious in case if there are multiple servers in the system and can’t be done manually. This job is automated by most of the admins with the help of a script which regularly checks for the disk space and sends a trigger based on the condition. These scripts are run using a task scheduler, which will run during non-business hours.

Popular Course in this category
Sale
Shell Scripting Training (4 Courses, 1 Project)4 Online Courses | 1 Hands-on Project | 18+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,725 ratings)
Course Price

View Course

Related Courses
All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)

Example:

Code:

$ServerList= Import-csv -path "C:\serverlist.csv"
ForEach ($s in $ServerList)
{$reportlist=Get-WmiObject win32_logicaldisk -ComputerName $s -Filter "Drivetype=3" -ErrorAction SilentlyContinue | Where-Object {($_.freespace/$_.size) -le '0.2'}
$vi=($reportlist.DeviceID -join ",").Replace(":",""
If ($reportlist)
{
$Eto = "test@test.com"
$Efro = "test@test.com"
$username = 'test@test.com'
$pwd = '#$5555'
$sub = "Disk space less than 20%"
$bdy = "In the server $s disk space is less than 20% in $vi"
$smser = "testadd@test.com"
$smmsg = New-Object System.Net.Mail.MailMessage($Efro,$Eto,$sub,$bdy)
$smtcli = New-Object Net.Mail.SmtpClient($smser, 587)
$smtcli.EnableSsl = $true
$smtcli.Credentials = New-Object System.Net.NetworkCredential($username, $pwd)
$smtcli.Send($smmsg)
}
}

Output:

PowerShell Administrator 2

3. Adding users from csv to an AD Group

Example:

Code:

write-host "Adding users from csv to a AD group"
Import-Csv “C:\vignesh\userlist.csv” | ForEach-Object {
$USPN = $_.SAN + “@test.com”
New-ADUser `
-DisplayName $_.DN `
-Name $_.”Na” `
-GivenName $_.”GN” `
-Surname $_.”SN” `
-SAN $_.”samname” `
-UserPrincipalName $USPN `
-Office $_.”Of” `
-EmailAddress $_.”emadd” `
-Description $_.”des” `
-AccountPassword (ConvertTo-SecureString “Tes$@123!” -AsPlainText -force) `
-ChangePasswordAtLogon $true `
-Enabled $true `
Add-ADGroupMember “testgroup” $_.”samname”;
write-host "User added successfully"
}

Output:

Adding users from csv to an AD Group

4. Check if patch is installed in a server or not

Example:

Code:

#list of servers to be checked
$servers = get-content -path  C:\servers.txt
#list of patch id's
$patdet = get-content -path  C:\padetails.txt
foreach ($ser in $servers)
{
foreach ($pa in $patdet)
{
Get-HotFix -id $pa -ComputerName $ser -OutVariable re -ErrorAction SilentlyContinue
if ($re -ne $null) {
write-host "Patch $pa is present in the $($ser)"
}
else {
write-host "patch $pa is not present in the $($ser)"
}
}
}

Output:
Check if patch is installed in a server or not

In the above example, a list of servers is maintained in one csv and the list of patch ids to be checked for installation in maintained in another csv. For each of the servers mentioned in the csv, all the patch ids are checked if it is installed or not. The server details and patch id’s can be mentioned in the same csv but it would be convenient to have them in different csv’s.

5. Deleting IIS logs older than 10 days

Code:

Write-Host "Welcome to the iis logs archive example"
$iislogpath = Import-Csv "C:\Vignesh\logpath.csv"
foreach($path in $iislogpath)
{
write-host "The iis log location is" $path
$deleteddays = "-10"
$CurrentDate = Get-Date
$noofdays = $CurrentDate.AddDays($deleteddays)
Get-ChildItem $Path -Recurse  | Where-Object { $_.CreationTime  -lt $noofdays } | Remove-Item
Write-Host "log files older than 7 days are deleted "
}

Output:

Deleting IIS logs older than 10 days

In the above script, a list of log locations is mentioned in the text file. Then in each of the paths, the files that are greater than 7 days are deleted. This can also be scheduled in a task scheduler and can be run daily during non-business hours.

Conclusion

Thus, the article covered in detail who is a PowerShell administrator and what are his roles and responsibilities. The mentioned roles are only a few but there are more tasks than a PowerShell administrator does on his day-to-day activities. The roles are explained with appropriate examples. In some cases, the PowerShell administrator is also responsible for the overall infrastructure of an organization.

Recommended Articles

This is a guide to PowerShell Administrator. Here we discuss the introduction to PowerShell Administrator, 5 different ways of running administrator with roles and responsibilities. You may also have a look at the following articles to learn more –

  1. PowerShell Send Mail
  2. PowerShell Get-Service
  3. PowerShell Rename Folder
  4. PowerShell Functions

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

4th of July Offer - Shell Scripting Course Learn More