Useful Powershell Commands
› Forums › Desktop Info › Useful Powershell Commands
Tagged: powershell
- This topic has 4 replies, 2 voices, and was last updated 3 years ago by
Bender.
-
AuthorPosts
-
-
1 December, 2019 at 10:27 am #2351
Let’s start a collection of useful Powershell commands that you use with Desktop Info. If we get even a small collection I’ll add a chapter to the manual.
I’ll start the ball rolling with this one that was sent to me by someone whose name I’ve forgotten (feel free to put your hand up). It returns a list of installed Microsoft applications. I’ve added this to the advanced ini file.
12CMD=active:6,font-size:75%,font-face:courier new,wide:1,file:powershell.exe,parameters:Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.Publisher -EQ “Microsoft Corporation” } | Select-Object DisplayName\, DisplayVersion | Out-String -Width 120 | Format-Table -Property @{Expression={$_.DisplayName}; Width=80},@{Expression={$_.DisplayVersion}; Width=20} -
2 December, 2019 at 7:24 pm #2358
Anonymous
Not exclusively powershell tho.
Robocopy(built-in windows tool)command to take backup of a folder to a external drive.
Change drives/folder to your needs, it will only copy new items. when using the /MIR switch it will also delete files in the target if files does not exists in the source, to keep an clean backup.
the log file is optionalrobocopy.exe C:\Data H:\backup\data /MIR /XA:H > C:\robobackup.log
I use this to backup a large folder of images after i have imported new photos
-
2 December, 2019 at 7:33 pm #2360
Anonymous
Quickly list “Application” eventlog, useful if some applications crash etc.
Get-EventLog -Log "Application"
-
3 December, 2019 at 2:00 pm #2362
There’s already an event log item but here’s Powershell code ready to copy/paste:
12345COMMENT=active:2,style:u,text:Application LogCMD=active:2,interval:30,font-size:80%,wide:1,file:powershell.exe,parameters: Get-EventLog -Log "Application" -Newest 3 | ForEach-Object {'{0} {1}' -f $_.TimeGenerated.ToString('dd MMM yyyy HH:mm')\,$_.Message}COMMENT=active:2,style:u,text:System LogCMD=active:2,interval:30,font-size:80%,wide:1,file:powershell.exe,parameters: Get-EventLog -Log "System" -Newest 3 | ForEach-Object {'{0} {1}' -f $_.TimeGenerated.ToString('dd MMM yyyy HH:mm')\,$_.Message}
-
-
11 December, 2019 at 1:20 pm #2385
Bender
If you use GitHub, you can query and display the number of new notifications from the GitHub API with PowerShell. For that you will first need a personal access token with the “notifications” permission for the account authentification via the command line (can be created in your GitHub account under Settings > Developer settings > Personal access token). I store it in a new environment variable named GITHUB_TOKEN, so that I don’t have to put it in my configuration file for Desktop Info. Then I use the following command to extract the number of new notifications (replace “username” with your GitHub username):
CMD=active:1,interval:900,file:powershell.exe,parameters:Invoke-RestMethod -Headers @{Authorization = 'Basic {0}' -f [System.Convert]::ToBase64String([char[]]\"username:$Env:GITHUB_TOKEN\");} -Uri https://api.github.com/notifications | Select-Object -ExpandProperty Count | Write-Host -NoNewline,text:GitHub,display:%4 new notifications
-
-
AuthorPosts
- The topic ‘Useful Powershell Commands’ is closed to new replies.