Useful Powershell Commands

Forums Desktop Info Useful Powershell Commands

Tagged: 

Viewing 3 reply threads
  • Author
    Posts
    • #2351 Reply
      GlennGlenn
      Keymaster

      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}
      
      0
    • #2358 Reply
      Avatarchadwill
      Participant

      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 1 week, 5 days ago by Avatarchadwill.
      0
    • #2360 Reply
      Avatarchadwill
      Participant

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

      Get-EventLog -Log "Application"

      0
      • #2362 Reply
        GlennGlenn
        Keymaster

        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}
        
        1+
        avatar
    • #2385 Reply
      AvatarBender

      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
      preview

      1+
      Glenn
Viewing 3 reply threads
Reply To: Useful Powershell Commands
Your information:




Do NOT follow this link or you will be banned from the site!