My Website

Search

    PowerShell nuggets

    Show env var

    ls env:\
    

    C:\Users\thumb\Documents\rp-utilities

    Show installed versions of .NET Framework

    Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version,Release -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version, Release
    

    Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version,Release -EA 0 | Where { $_.PSChildName -match '^(?!S)\p{L}'} | Select PSChildName, Version, Release

    
    #### Counting files in a folder
    
    The @(..) is the array subexpression operator. This ensures that the output of Get-ChildItem is treated as an array, even if it finds zero files or only one file. This is important because single objects don't have a .Count property, but arrays do (even an empty array has a .Count of 0).
    
    

    $is_dg400_present = @(Get-ChildItem -Path $datagate_family_changes_path -Filter "dg400*" -File).Count

    
    ### Count
    
    #### Backup SQL Server
    
    [[sql-server-backup-with-powershell]]
    
    #### Work with processes
    
    
    Get processes that start with something (msedge in this case)
    
    

    Get-Process -Name msedge*

    
    Stop all processes that start with something:
    
    

    Stop-Process -Name msedge* -force

    List all files that aren't in node_modules or a folder that starts with a period.

    ls *.* -rec | Where-Object { $_.FullName -notmatch 'node_modules|\\\.[^\\]+\\' } | sort LastWriteTime | select Name, LastWriteTime, directoryname | out-file -width 1000 member.lst