Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ======================================
- Powershell Basics
- ======================================
- #Approved Verbs for PowerShell Commands
- #https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.2
- #You are looking for help while using Powershell - displays how-to information for commands
- get-help
- #Most helpful help command - Output examples
- help get-service -Examples
- help get-service -full
- help get-service -online
- #update local help files
- update-help
- #Used to search installed commands
- get-command
- Help get-command
- Help Get-Command -examples
- #You are looking for a command to work with IP Address Configurations on a Windows System
- get-command -name *IP* | More
- get-command -Name *IP* -Module Net*
- Get-command -Name *IP* -Module NetTCPIP
- #Get history of type commands via Powerhell Console
- Get-history
- #Get-member - gets properties and methods of objects - used to see what makes up an object
- Help Get-Member
- Get-service | Get-Member
- #List Powershell Modules
- #List installed Modules
- Get-InstalledModule
- #Provides information about all available modules. Remember that installed modules need to be explicitly imported after installation
- Get-Module -ListAvailable
- #Pipelining and Objects
- Get-service | Select-Object Name,MachineName,Status
- Get-Service | Select-Object Name,MachineName,Status | Get-Member
- Get-Service | Where-Object status -eq "Stopped" | More
- #See the last time the system had a reboot. The easiest way to see this is by finding the 1074 System event in Event Viewer. This event #message signifies that the system has restarted.
- get-command get-*Event*
- help get-eventlog -Examples
- get-eventlog -LogName System | gm
- Get-EventLog -log system –newest 1000 |
- where-object eventid –eq '1074' |
- format-table machinename, username, timegenerated –autosize
- help Get-ComputerInfo
- help Get-ComputerInfo -Examples
- Get-ComputerInfo | more
- Get-ComputerInfo -Property *memory*
- #Get Basic Info about Client/server Hostname , Domain the machine belongs to, OSname, OS Version,OS build number , Patches installed , #Windows version and Bios InFo
- Get-computerinfo CsDNSHostname, CsDomain, OsName, OsVersion, OsBuildnumber, OsHotfixes, WindowsVersion, BiosSMBBIOSVersion
- #Get event logs of computer who is using the machine , Who logged in at what time
- Get-Eventlog -LogName Security -Newest 500 -InstanceID 4624 | Format-Table -Wrap -AutoSize | out-file -FilePath c:\admin\login.txt
- #List Installed Software , Version, PAckagename and installdate
- Get-WmiObject win32_product | Select-Object Name,Version,PackageName,InstallDate
- #Display only Installed Features and Roles and List Installed Software , Version, PAckagename and installdate and output to a file #c:\admin\servername+filename.txt
- Get-WindowsFeature | Where-Object {$_. installstate -eq "installed"} | Out-File C:\Admin\$env:COMPUTERNAME+InstalledFeaturesAndRoles.txt ; Get-WmiObject win32_product | Select-Object Name,Version,PackageName,InstallDate | Out-File C:\Admin\$env:COMPUTERNAME+InstalledSoftware.txt
- #Gets an orphaned computer instantly back on the domain or fixes its account.
- Reset-computermachinepassword
- ipconfig
- ipconfig /all
- ipconfig | gm
- Get-Command get-NetIP*
- Get-NetIPAddress
- Get-NetIPConfiguration
- GCM get-*DNS*
- GCM get-DNSClient*
- Get-DnsClient
- Get-DnsClientCache
- Get-DnsClientServerAddress
- ping 4.2.2.1
- tracert 4.2.2.1
- Test-NetConnection -TraceRoute 4.2.2.1
- Test-NetConnection -CommonTCPPort HTTP -ComputerName 4.2.2.1
- Test-NetConnection -CommonTCPPort HTTP -ComputerName mbl.is
- Test-Netconnection random.server.local -port 1433
- #Map a Network Drive > Use SMB or simple message block so we need to search for SMB related commands
- Get-Command *SMB*
- Get-Command *SmbMapping
- Help New-SmbMapping -examples
- New-SMBmapping -localPath w: -remotepath \\DC01\Share
- Get-smbmapping
- # File System CREATE FILES FROM HERE
- # So let's say you are looking for files a user stored on a network drive, yet they don't know where or what they are named; just the #type of file. That's not a problem with powerShell.
- Help get-childitem
- Get-ChildItem -Path w:\ -Recurse
- Get-ChildItem -Path w:\ -Recurse | gm
- Get-ChildItem -Path w:\ -Recurse | where Extension -EQ '.PNG'
- Get-ChildItem -Path w:\ -Recurse | where Extension -EQ '.PNG' | ft Directory,Name,LastWriteTime
- #Now lets say I want to move files from
- Gcm *copy*
- help Copy-Item -Examples
- copy-item w:\ -Destination c:\CopiedFolder -Recurse -Verbose
- dir c:\CopiedFolder -recurse
- move-item c:\CopiedFolder -Destination c:\MovedFolder -verbose
- dir c:\MovedFolder -Recurse
- Rename-Item c:\MovedFolder -NewName c:\RenamedFolder
- dir c:\
- ###PS Remoting ### for Multiple computers via GPO https://4sysops.com/wiki/enable-powershell-remoting/#remotely-with-group-policy
- #starts the session listener and configures the windows firewall for remoting
- Enable-PSRemoting
- #Configure permission via GUI for Security Group for PS remoting
- Set-PSSessionConfiguration -Name Microsoft.Powershell -ShowSecurityDescriptorUI
- #Enable Firewall rules for WMI (legacy PS remoting stuff)
- Get-NetFirewallRule | where DisplayName -Like "*Windows Management Instumentation*" | Set-NetFirewallRule -Enable True -Verbose
- #Using Computername parameter
- Get-Service –computername $ComputerName | select Name,Status
- #Using PSSession (useful for real time work/management)
- Gcm *-PSSession
- #Create a PSSession
- $ComputerName = “Client02”
- $credential = Get-Credential
- New-PSSession -ComputerName $ComputerName -Credential $credential
- Enter-PSSession -Name $ComputerName
- Get-PSSession
- Enter-PSSession -Id 2
- Get-PSSession
- Remove-PSSession -id 2
- Get-PSSession
- #Running command on Remote System , Invoke-command is useful in Scripting
- help Invoke-command
- $ComputerName = "Client02"
- $credential = Get-Credential
- Invoke-command -ComputerName $ComputerName -Credential $credential -ScriptBlock { get-service -ComputerName $ComputerName }
- invoke-command -ComputerName $ComputerName -Credential $credential -ScriptBlock { get-service -ComputerName $using:ComputerName }
- $data = invoke-command -ComputerName $ComputerName -Credential $credential -ScriptBlock { get-service -ComputerName $using:ComputerName }
- $data | gm
- $Data | Select Name,Status,Description
- #On PowerShell Core
- # Running Remote Commands
- invoke-command -ComputerName DC01 -cred (get-credential) -ScriptBlock { Get-ADUser -Identity felixb | format-list }
- #Using New-Cimsession (useful for Legacy machines)
- $ComputerName = 'Client02'
- $credential = Get-Credential
- Help New-Cimsession
- $cimsession = New-CimSession -ComputerName $ComputerName -Credential $Credential
- $cimsession
- Get-CimSession
- Help Get-DNSClientServerAddress
- Get-DNSClientServerAddress -CimSession $CimSession
Add Comment
Please, Sign In to add comment