Useful Powershell Commands

Forums Desktop Info Useful Powershell Commands


Viewing 3 reply threads
  • Author
    • #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.

      CMD=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}
    • #2358

      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 optional

      robocopy.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

      • This reply was modified 9 months, 3 weeks ago by Avatarchadwill.
    • #2360

      Quickly list “Application” eventlog, useful if some applications crash etc.

      Get-EventLog -Log "Application"

      • #2362

        There’s already an event log item but here’s Powershell code ready to copy/paste:

        COMMENT=active:2,style:u,text:Application Log
        CMD=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 Log
        CMD=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}
    • #2385

      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 | Select-Object -ExpandProperty Count | Write-Host -NoNewline,text:GitHub,display:%4 new notifications

Viewing 3 reply threads
  • The topic ‘Useful Powershell Commands’ is closed to new replies.
Do NOT follow this link or you will be banned from the site!