working on it ...

Filters

Explore Public Snippets

Sort by

Found 8,673 snippets

    public by DinhoPutz modified Feb 5, 2019  50  0  3  0

    Substituir espaço por tração/underline no Windows com PowerShell

    Código abaixo pode ser utilizado para substituir espaço por tração/underline no Windows com PowerShell, filtrando por tipo de arquivo, ou se preferir, basta adaptar qualquer que seja a necessidade.
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por traço  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","-" }
    
    
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por underline  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","_" }
    
    
    # Procura por arquivo MP3 e remove os espaços  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","" }
    
    
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por traço  
    ls *.doc | Rename-Item -NewName { $_.name -replace " ","-" }
    
    
    

    public by DinhoPutz modified Jan 30, 2019  52  3  3  0

    Contar quantas linhas de código tem um projeto (PowerShell)

    Alguns usuários relataram que o código não esta contando linhas em sub diretórios. Nos testes que realizei em mais de um ambiente o mesmo não ocorreu. Caso alguém passe pelo mesmo, comente comigo em qual situação isso ocorre, gostaria de saber qual a particularidade da situação.
    <#  
    Usando o Microsoft PowerShell para contar quantas linhas de código tem um projeto.
    Ness exemplo estamos contados as linhas de arquivos .js e .html.
    #>
     
    (dir -include *.js,*.html,*.MD,*.php -recurse | select-string .).Count															

    public by andrewhart098 modified Nov 24, 2017  400  6  4  0

    Powershell script that list all previously known wifi networks and their associated passwords

    Powershell script that list all previously known wifi networks and their associated passwords: wifi-remember.ps1
    # The number of lines skipped in the following command may need to be altered if "Group policy profiles" are available
    $profiles = $(netsh wlan show profiles)  -split "\n" | Select-Object -Skip 9 | Select -SkipLast 1
    
    foreach($profile in $profiles)
    {
        $network = $profile.Split(":")[1].Replace(" ", "")
        $info = $(netsh wlan show profile $network key=clear)
        $key = $info | Select-String -Pattern "Key Content"
        $cleanKey = If (!$key.Line) {"No Password Required"} Else {$key.Line.Split(":")[1].Replace(" ", "")}
        Write-Output ("{0}  -  {1}" -f $network,$cleanKey)
    }
    
    

    public by charlwillia6 modified Aug 14, 2017  470  3  3  0

    Powershell command to rename files to lowercase

    Powershell command to rename files to lowercase: batch_rename_to_lowercase.txt
    Get-ChildItem "C:\Path\To\Pics" -recurse | Where {-Not $_.PSIsContainer} | Rename-Item -NewName {$_.FullName.ToLower()}
    
    																								

    public by RexPhillips modified Jul 24, 2017  325  2  4  0

    RenameFilesInDirectoryWildcard

    Powershell snippet to rename files in a directory in a batch mode.
    dir | rename-item -NewName {$_.name -replace "DEV","PROD"}

    public by mateothegreat modified Jun 15, 2017  204  0  2  0

    Get list of programs that can be uninstalled automatically.

    Get list of programs that can be uninstalled automatically.: get_uninstallable_programs.ps1
    PS C:\Windows\system32> New-PSDrive -Name Uninstall -PSProvider Registry -Root HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    
    PS C:\Windows\system32> dir Uninstall: | Get-ItemProperty -Name DisplayName, InstallDate, Publisher, InstallLocation, UninstallString, ModifyPath, EstimatedSize -ErrorAction SilentlyContinue | Sort-Object -Property DisplayName -ErrorAction SilentlyContinue
    
    

    public by rjminick modified Dec 1, 2016  7572  1  4  0

    Search for Active Directory Groups

    Search for Active Directory Groups matching filter
    Get-ADGroup -Filter 'Name -like "I-ADE42*"' |  FT Name,SamAccountName -A

    public by javalonson modified Apr 14, 2016  2580  2  4  0

    Search text in files for PowerShell

    Search text in files for PowerShell. Change directory, ext, text_to_search and outputfile as you choice.
    dir directory *.ext -R | Select-String text_to_search | Out-File "outputfile.txt"
    

    public by virgilwashere modified Jan 4, 2016  3724  7  6  0

    Powershell advanced function syntax

    Powershell advanced function syntax with most parameters added
    <# Insert Comment-based Help template snippet here 
    #>
    function Verb-Noun
    {
        [CmdletBinding(DefaultParameterSetName='Parameter Set 1', 
                      SupportsShouldProcess=$true, 
                      PositionalBinding=$false,
                      HelpUri = 'http://www.microsoft.com/',
                      ConfirmImpact='Medium')]
        [OutputType([String])]
        Param
        (
            # Param1 help description
            [Parameter(Mandatory=$true, 
                       ValueFromPipeline=$true,
                       ValueFromPipelineByPropertyName=$true, 
                       ValueFromRemainingArguments=$false, 
                       Position=0,
                       ParameterSetName='Parameter Set 1')]
            [HelpMessage('help description')]
    		[ValidateNotNull()]
            [ValidateNotNullOrEmpty()]
            [ValidateCount(0,5)]
            [ValidateSet("sun", "moon", "earth")]
            [Alias("p1")] 
            $Param1,
    
            # Param2 help description
            [Parameter(ParameterSetName='Parameter Set 1')]
            [AllowNull()]
            [AllowEmptyCollection()]
            [AllowEmptyString()]
            [ValidateScript({$true})]
            [ValidateRange(0,5)]
            [int]
            $Param2,
    
            # Param3 help description
            [Parameter(ParameterSetName='Another Parameter Set')]
            [ValidatePattern("[a-z]*")]
            [ValidateLength(0,15)]
            [String]
            $Param3
        )
    
        Begin {
        }
    	
        Process {
            if ($pscmdlet.ShouldProcess("Target", "Operation"))
            {
            }
        }
        
    	End {
        }
    }
    

    public by virgilwashere modified Jan 4, 2016  2195  3  6  0

    Comment-based Help for function or script

    Comment-based Help for function or script
    <#
     .Notes
     NAME:		$($MyInvocation.MyCommand.Name)
     AUTHOR:	$($env:USERNAME)
     
     CREATED:	dd/MM/yyyy
     LASTEDIT:	$(Get-Date -f 'dd/MM/yyyy')
     
     Version:	1.0 Initial Release
    			1.1 Added Feature X
     
     .Synopsis
     One line blurb that discusses cmdlet
    
     .Description
     Multi-line description of cmdlet
    
     .Parameter ParameterName1
     Description of ParameterName1
    
     .Parameter ParameterName2
     Description of ParameterName2
    
     .Inputs
     Information about the types of input objects accepted
    
     .Outputs
     Information about the objects returned as output from the cmdlet
    
     .Example
     Detailed example.  Ideally there should be an example for each set of Parameters and a pipeline example.
    
     .Example
     Additional example
    
     .LINK
     Related cmdlets or relevant URL
    #>
    • Public Snippets
    • Channels Snippets