Last active
October 19, 2016 08:21
-
-
Save lanekatris/5897772 to your computer and use it in GitHub Desktop.
Usefull Powershell Commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Import all modules available on the system | |
| Get-Module -ListAvailable | Import-Module | |
| # Sort directory contents | |
| Get-ChildItem -path . | sort-object lastwritetime -descending | |
| # Start a new powershell prompt and give it a command to execute | |
| Start-Process powershell "-noexit -command `"cd $place`"" | |
| # Run a cmd command and capture it's output | |
| $a = ipconfig | |
| # Find the error code of the last command that is external, greater than 0, not successful | |
| rasdial.exe | |
| $LastExitCode | |
| # Find if the last cmd-let was successful | |
| $? | |
| # Access error objects | |
| $error | |
| # Match a string when filtering | |
| get-childitem | where { $_.Name -match "visual"} | |
| # Rename multiple files | |
| get-childitem *.sql | rename-item -newname {$_.Name + "idk"} | |
| # Move multiple files | |
| move-item .\*.sql '..\other place\subdir' | |
| # Open multiple files | |
| get-childitem .\*.png |foreach-object {start-process $_.FullName -wait} | |
| # Access computer remotely using PSSession | |
| $creds = Get-Credential | |
| $server = New-PSSession -ComputerName mycomputername -Credential $creds | |
| Enter-PSSession $server | |
| # Compress a file using 7zip - put anything for *.txt (selector) | |
| 7za a -t7z archiveName.7z *.txt | |
| # Create new folder | |
| new-item -type directory | |
| # Expand a property name to show completely | |
| get-service | select -expandProperty Name | |
| # Start service on local machine | |
| Get-Service -Name "Mongos" | Start-Service | |
| # Start service on remote machine | |
| Get-Service -Name "Mongos" -ComputerName loon-api | Set-Service -Status Running | |
| # http://stackoverflow.com/questions/12644500/copy-item-is-does-not-retain-filename-or-extension-at-destination | |
| copy-item C:\TEMP\installation.msi -Destination Q:\ | |
| # Access IIS features | |
| Import-Module WebAdministration | |
| # Create a web application in IIS | |
| # http://www.iis.net/learn/manage/powershell/powershell-snap-in-creating-web-sites-web-applications-virtual-directories-and-application-pools | |
| New-Item 'IIS:\Sites\Default Web Site\DemoApp' -physicalPath c:\test -type Application |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment