5 Windows administration tasks that can be automated using PowerShell – TechRepublic

Posted: January 9, 2021 at 3:03 pm

Windows admins can leverage a great deal of automation by integrating PowerShell (PS) into their daily tasks to make short work of even the most cumbersome administrative tasks.

Image: iStock/BestForBest

Administrators have a tough, often tedious role to fill. Keeping everything going can be just as (if not more) difficult than swooping in to fix something that isn't working properly. Even relatively simple tasks, like creating new computer objects in Active Directory (AD) or ensuring that the devices on the network are all patched and operating optimally can be very time consuming when you factor in the sheer number of devices being managed.

SEE: TechRepublic Premium editorial calendar: IT policies, checklists, toolkits, and research for download (TechRepublic Premium)

I'm a big fan of automating as much as possible because it provides the following:

Lastly, it's better to work smarter, not harder, especially when it comes to types of repeat tasks that IT pros must perform.

Here are a few tasks common to IT pros in the hopes that they help you to work smarter, while inspiring you to apply that thought process to your organization's needs and make the necessary changes to automate frequently accessed tasks for a simpler, more efficient workflow.

The cmdlets below reference variables, beginning with the "$" character. These are labeled with the data the variable should be holding to make the cmdlet execute without error. These must first be stated in your script as shown in the sample below when setting the OU path variable:

$OU=OU=Office,OU=Dept,OU=Company,DC=DomainName,DC=DomainExt

While the PowerShell cmdlets may be duplicated within your script, it is generally considered a best practice to keep the code to a minimum. This means eliminating duplicate code as much as possible. One way I've found that helps keep code nice and tidy, while making the script efficient, is to leverage a cmdlet such as Import-CSV and create a looping condition so that the cmdlet runs against all items within your CSV file with a column named "Computers" to create the desired effect, as shown in the example below when setting computer names:

Import-Csv -Path $csv | ForEach ( { New-ADComputer -Name "$($_.Computers)"

ForEach ( { New-ADComputer -Name "$CompName" -Server $dc -Path $ou -Enabled $True } )

$comp = Get-ADComputer -Filter {Name -like $custom}

foreach ($station in $comp){Add-ADGroupMember -Identity $group -Members $station}

Get-ADComputer -SearchBase $searchOU -Filter {LastLogon -lt $time -and enabled -eq $true} -Properties LastLogon, description | Select-Object Name,DistinguishedName, description, enabled,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.LastLogon)}} | export-csv $logfile -notypeinformation

Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -AutoReboot | Out-File "C:$Nodes-$(Get-Date -f yyyy-MM-dd)-MSUpdates.log" -Force

$VM = Get-SCVMHost -VMMServer "$VMMServer" -ComputerName "$CompName" | Get-SCVirtualMachine | Where-Object { $_.Status -eq "PowerOff" }

$VM | Start-SCVirtualMachine

Our editors highlight the TechRepublic articles, downloads, and galleries that you cannot miss to stay current on the latest IT news, innovations, and tips. Fridays

Read the original post:

5 Windows administration tasks that can be automated using PowerShell - TechRepublic

Related Posts