> powershell -executionpolicy bypass -File .\RemoveApps.ps1
> (get-childitem -Path d:\projects -Recurse -Directory -Depth 2).FullName
- Delete file include sub-folder
Get-ChildItem -Include *.exe.config -Recurse | foreach { $_.Delete() }
- Copy a file to 1st level sub-folder
> Get-ChildItem -Path . -Directory -Recurse -Depth 0 | foreach { Copy-Item .gitignore $_ }
Get-ChildItem *ESB.*\*.Runner.exe | % { & $_.FullName install }
Get-Service *ESB* | Where-Object {$_.Status -eq "Stopped"}
Get-Service *ESB* | Where-Object {$_.Status -eq "Stopped"} | Start-Service
- Scheduling a Task to Run these PowerShell Functions
C:\Windows\System32\schtasks.exe /create /TN MonitorServ /ST 12:30 /SC DAILY /RI 10 /TR “powershell.exe C:\ Get-PSServiceStatus”
This newly created Windows Task Schedule will run the Get-PSServiceStatus function daily starting at 12:30 and every 10 minutes.
- Get file or folder permissions
> (get-acl <folder name>).access | ft IdentityReference,FileSystemRights,AccessControlType,IsInherited,InheritanceFlags -auto
> Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
- Example 1: Delete a registry value
Remove-ItemProperty -Path "HKLM:\Software\SmpApplication" -Name "SmpProperty"
- Example 2: Delete a registry value from the HKCU location
PS C:\> Set-Location HKCU:\Software\MyCompany\MyApp
PS HKCU:\Software\MyCompany\MyApp> Remove-ItemProperty -Path . -Name "Options" -Confirm
- Example 3: Remove a registry value by using the pipeline
Get-Item -Path HKLM:\Software\MyCompany | Remove-ItemProperty -Name NoOfEmployees
- Multiple git init and commit
>Get-ChildItem -Directory | % { Push-Location $_; git init ; git add . ; git commit -a -m "Init" ;Pop-Location }
>Get-ChildItem -Directory | % { Push-Location $_; Write-Host $_.FullName -foregroundColor "green" ; git status ;Pop-Location }
> Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
> Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
> Start-Service sshd
> Get-Service sshd
> Set-Service -Name sshd -StartupType 'Automatic'
- CONFIGURING THE DEFAULT SHELL FOR OPENSSH IN WINDOWS
> New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\PowerShell\7\pwsh.exe" -PropertyType String -Force
> Get-ChildItem cert:\ -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and $_.NotAfter -lt (Get-Date)} | Select-Object -Property FriendlyName,NotAfter
- How to find expired Certificates with PowerShell (export to html)
> Get-ChildItem cert:\ -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and $_.NotAfter -lt (Get-Date)} | Select-Object -Property FriendlyName,NotAfter | ConvertTo-Html | Set-Content C:\Temp\ExpiredCerts.htm
- Certificates expires soon
> Get-ChildItem cert:\ -Recurse | Where-Object {$_ -is [System.Security.Cryptography.X509Certificates.X509Certificate2] -and $_.NotAfter -gt (Get-Date) -and $_.NotAfter -lt (Get-Date).AddDays(30)} | Select-Object -Property FriendlyName,NotAfter
> Get-ChildItem -Path cert:\\"<thumbnail>" -Recurse
- Get Alias
Get-Alias -Definition Invoke-WebRequest | Format-Table -AutoSize