powershell

A collection of 3 posts
windows

Powershell批量限制程序网络访问

$exeFileNames = Get-ChildItem -Path "C:\apps folder" -Recurse –File -Include "*.exe" | % { $_.FullName } foreach ($exeFileName in $exeFileNames) { # Code to execute for each item Write-Host "----" Write-Host $exeFileName $existFirewallRule = Get-NetFirewallRule -DisplayName $exeFileName | Where-Object { $_.Action -eq 'Block' -and $_.Direction -eq 'Outbound' -and $_.Enabled -eq $True} if ($null -eq $existFirewallRule) { $newRule = New-NetFirewallRule -DisplayName $e
windows

Powershell 卸载程序

function Uninstall-Application { $appName = $($args[0]) Write "application to uninstall: $appName" $uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -Match $appName } $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $appName } if($uninstall32){ if($uninstall32.QuietUninstallString){ Write ("uninstall32 Quiet
powershell

Powershell 操作 windows更新

定义更新搜索 $Criteria = "IsInstalled=0 and Type='Software'" 搜索可用的更新 $Searcher = New-Object -ComObject Microsoft.Update.Searcher $SearchResult = $Searcher.Search($Criteria).Updates 下载更新 $Session = New-Object -ComObject Microsoft.Update.Session $Downloader = $Session.CreateUpdateDownloader() $Downloader.Updates = $SearchResult $Downloader.Download() 安装更新 $Installer = New-Object -ComObject Microsoft.Update.Installer $Installer.Updates = $SearchResult $Result = $Installer.Install() 检查是否需要重启 $Resu
1 min read