--- type: "topic" assigned: "" created: "2024-02-25T00:52:01.394Z" updated: "2024-03-21T16:42:43.661Z" --- # PowerShell ## Clear History ```bash mklink /J .PSReadLine "C:\Users\phares\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine" mklink /J .PSReadLine "C:\Users\mikep\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine" mklink /J .PSReadLine "C:\Users\lphar\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine" ``` ```PowerShell # https://stackoverflow.com/questions/13257775/powershells-clear-history-doesnt-clear-history explorer C:\Users\phares\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine notepad C:\Users\phares\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt Clear-History [Microsoft.PowerShell.PSConsoleReadLine]::ClearHistory() ``` ```VSCode Find & Replace cls\n & 'c:\\Users\\phares\\.vscode.*\n dotnettools.csharp-.*\n ``` ## VSCode ```PowerShell code --show-versions --list-extensions | % { "code --install-extension $_".Split('@')[0] } ``` ```PowerShell $extensionsArray = code --show-versions --list-extensions foreach ($extension in $extensionsArray) { $segments = $extension.Split('.') $namespace = $segments[0] $segmentsJoined = $segments[1..($segments.length-1)] -join "." $segments = $segmentsJoined.Split('@') $name = $segments[0] $segmentsJoined = $segments[1..($segments.length-1)] -join "." Write-Host "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/$namespace/vsextensions/$name/$segmentsJoined/vspackage" } ``` ```PowerShell $json = Get-Content 'C:\Users\phares\.vscode\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-infineon-code.txt' $json = Get-Content 'C:\Users\phares\.vscode-insiders\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-infineon-insiders.txt' $json = Get-Content 'C:\Users\phares\.vscode-oss\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-infineon-codium.txt' ``` ```PowerShell $json = Get-Content 'C:\Users\mikep\.vscode\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-desktop-code.txt' $json = Get-Content 'C:\Users\mikep\.vscode-insiders\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-desktop-insiders.txt' $json = Get-Content 'C:\Users\mikep\.vscode-oss\extensions\extensions.json' | Out-String | ConvertFrom-Json $extensions = ($json.identifier.id) | Sort-Object | Out-File 'L:\Git\VS-Code-Settings\list-extensions-desktop-codium.txt' ``` ```PowerShell Compress-Archive -CompressionLevel NoCompression -Path 'C:\input' -DestinationPath 'C:\output.zip' Compress-Archive -CompressionLevel NoCompression -Path 'D:\Downloads\.Microsoft Visual Studio\2022\vs_BuildTools\vs_BuildTools' -DestinationPath 'D:\Downloads\2023\vs_BuildTools.zip' Compress-Archive -CompressionLevel NoCompression -Path 'C:\Program Files\APC' -DestinationPath 'D:\Downloads\2023\APC-v2.4.4.1.zip' Compress-Archive -CompressionLevel NoCompression -Path 'C:\Program Files (x86)\EAF\EAF Management Client\v4.2.0' -DestinationPath 'D:\Downloads\2023\EAF-Management-Client-v4.2.0.zip' Compress-Archive -CompressionLevel NoCompression -Path 'L:\Git\code-server' -DestinationPath 'D:\Downloads\2023\code-server-v4.17.1.zip' Compress-Archive -CompressionLevel NoCompression -Path 'L:\Git\Notes-EC-Documentation\EC-Documentation\node_modules\prettier' -DestinationPath 'D:\Downloads\2023\prettier-v3.0.0.zip' ``` ## C# ### I want to delete all bin and obj folders to force all projects to rebuild everything ```PowerShell # https://stackoverflow.com/questions/755382/i-want-to-delete-all-bin-and-obj-folders-to-force-all-projects-to-rebuild-everyt Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } Get-ChildItem .\ -include TestResults -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } Get-ChildItem .\ -include node_modules -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } ``` ``` C:\Program Files\FreeFileSync C:\Program Files\Git C:\Program Files\Git\mingw64 C:\Program Files\Git\usr C:\Program Files\Java\jdk-22 C:\Program Files\nodejs\node_modules\npm C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\arborist C:\Program Files\nodejs\node_modules\npm\node_modules\cross-spawn\node_modules\which C:\Program Files\nodejs\node_modules\npm\node_modules\cssesc C:\Program Files\nodejs\node_modules\npm\node_modules\mkdirp C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp C:\Program Files\nodejs\node_modules\npm\node_modules\nopt C:\Program Files\nodejs\node_modules\npm\node_modules\qrcode-terminal C:\Program Files\nodejs\node_modules\npm\node_modules\semver C:\Program Files\nodejs\node_modules\npm\node_modules\which C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\usr C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\DIA SDK C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\Llvm C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\Llvm\x64 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133 C:\Program Files (x86)\Nmap\zenmap C:\Program Files (x86)\OpenOffice 4\program\python-core-2.7.18 C:\Program Files (x86)\Windows Kits\10 C:\Program Files (x86)\WindowsPowerShell\Modules\Pester\3.4.0 ``` ```PowerShell Add-WindowsFeature AD-Domain-Services Get-ADUser -Filter * -Properties ScriptPath | Group-Object ScriptPath | Select-Object Count,Name get-ADUser -filter "scriptpath -eq 'sample.bat'" -Properties scriptpath | select name, samaccountname, scriptpath Get-ADUser -Filter "Name -eq 'ecapcsvc'" Get-ADUser -Filter "Name -eq 'ecapcsvc'" -SearchBase "DC=AppNC" -Properties "mail" -Server lds.Fabrikam.com:50000 Get-ADUser -Filter "Name -eq 'ecapcsvc'" Get-ADUser -Filter "Name -eq 'ecapcsvc'" -Properties * Get-ADGroup -Filter "Name -eq 'EC-MES-PRJ-SPC-SI-R-L'" -Properties members Get-ADGroupMember -Identity MES-APP-OpenInsight-Users | Select-Object name, objectClass,distinguishedName | export-csv D:\Tmp\admingroup.csv ``` ```PowerShell Save-Module -Name PSWindowsUpdate -Path "D:\Downloads\2023" -Repository PSGallery mkdir "C:\Test\Modules\PowerShellGet\" Save-Module -Name PowerShellGet -Path "C:\Test\Modules" -Repository PSGallery -MaximumVersion 2.1.0 Get-ChildItem -Path C:\Test\Modules\PowerShellGet\ Save-Module -Name PSWindowsUpdate -Path "C:\Test\Modules" -Repository PSGallery Save-Module -Name Nuget -Path "C:\Test\Modules" -Repository PSGallery Install-WindowsUpdate –AcceptAll Install-WindowsUpdate –AcceptAll –IgnoreReboot ``` ```bash "C:/Program Files/WindowsPowerShell/Modules" "C:/Windows/System32/WindowsPowerShell/v1.0/Modules" ``` ```PowerShell $wslFile="$env:temp\wsl-vpnkit.tar.gz" curl.exe --output "$wslFile" "https://artifactory.intra.infineon.com/artifactory/gen-it-pfw-files-local/WSL2-defaults/wsl-vpnkit-0.3.8.tar.gz" $wslDir="$env:userprofile\wsl-distros" if (!(Test-Path "${wslDir}")) {New-Item "${wslDir}" -ItemType Directory } wsl --import "wsl-vpnkit" "$wslDir" "$wslFile" Remove-Item "$wslFile" ``` ```PowerShell winget install vscodium winget install git.git winget install putty.putty winget install winscp.winscp winget install DominikReichl.KeePass ``` ```PowerShell unblock-File -path "C:\Users\phares\AppData\Local\IFXApps\RDCMan\2.93.1431.0\RDCMan.exe" ``` ```PowerShell whoami whoami /groups ``` ```PowerShell cmd /C mklink /D C:\local\path \\UNC\path\folder ``` ```PowerShell # https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-7.4 Start-Process -FilePath "myfile.txt" -WorkingDirectory "C:\PS-Test" -Verb Print ``` ```PowerShell $username = "infineon\ecfisysadmin" $password = "asdf" $startWithElevatedRights = "notepad" $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force)) $ps = Start-Process -PassThru -FilePath powershell -Credential $credentials -ArgumentList '-noprofile -command &{Start-Process ', $startWithElevatedRights, ' -Wait -verb runas}' $ps.WaitForExit() ```