PowerShell Basics Flashcards
Get basic system information, including OS, architecture, version, etc.
Get-ComputerInfo
Retrieve or Check logs for critical system events.
Get-EventLog -LogName System -EntryType Error -Newest 10
List all installed software on the system.
Get-WmiObject -Class Win32_Product
Check the free and used space on all disks.
Get-PSDrive -PSProvider FileSystem
Create a new user in Active Directory (if you’re using AD).
New-ADUser -SamAccountName “newuser” -Name “New User” -GivenName “New” -Surname “User” -UserPrincipalName “newuser@domain.com” -AccountPassword (ConvertTo-SecureString “P@ssword1” -AsPlainText -Force) -Enabled $true
Change the password of an existing user account.
Set-ADAccountPassword -Identity “username” -NewPassword (ConvertTo-SecureString “NewPassword123” -AsPlainText -Force)
Add a user to a specific Active Directory group.
Add-ADGroupMember -Identity “GroupName” -Members “username”
List all users in a specific Active Directory group.
Get-ADGroupMember -Identity “GroupName”
Start or stop a specific service
Start-Service -Name “wuauserv”
Stop-Service -Name “wuauserv”
Retrieve the status of a specific service.
Get-Service -Name “wuauserv”
Check if there are any pending Windows updates
Get-WindowsUpdate
Install available Windows updates.
Install-WindowsUpdate -AcceptAll -AutoReboot
Perform a backup of a folder or directory using PowerShell.
Copy-Item -Path “C:\SourceFolder” -Destination “D:\BackupFolder” -Recurse
Create a scheduled task to run a script or command at a specified time.
$Action = New-ScheduledTaskAction -Execute “powershell.exe” -Argument “C:\Scripts\Backup.ps1”
$Trigger = New-ScheduledTaskTrigger -At 3:00AM -Daily
Register-ScheduledTask -Action $Action -Trigger $Trigger -TaskName “DailyBackup” -User “Administrator” -Password “Password123”
Export all user data from Active Directory to a CSV file.
Get-ADUser -Filter * -Property DisplayName, EmailAddress | Export-Csv -Path “C:\UsersExport.csv” -NoTypeInformation
Get the health status of all drives (SMART status).
Get-WmiObject -Class Win32_DiskDrive | Select-Object DeviceID, Model, Status
Verify the integrity of files using a checksum (e.g., SHA256).
Get-FileHash “C:\path\to\file.exe” -Algorithm SHA256
Retrieve the last logon time of a specific user.
Get-ADUser “username” -Properties LastLogonDate
Enable or disable an Active Directory user account.
Disable-ADAccount -Identity “username”
Enable-ADAccount -Identity “username”
Export comprehensive system information to a text file for reporting purposes.
Get-ComputerInfo | Out-File “C:\SystemInfo.txt”