结合powershell和cmd创建一个批处理文件



我不是编码员,但我有一些基本的能力将一些脚本混合在一起,通常会得到一些对我有用的东西,但这远远超出了我的理解范围。我正在尝试将 3 件事合并到一个批处理文件中。它本质上是一个多合一的解决方案,可以关闭Windows 10隐私设置并删除一些后台应用程序。我可以在 powershell 中很好地运行命令,但我想通过一个批处理脚本自动化整个事情:

  1. 使 Windows 10 隐私设置脚本保持最新。这是通过powershell中的以下命令完成的:

    (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/hahndorf/Set-Privacy/master/Set-Privacy.ps1') | out-file .Set-Privacy.ps1 -force 
    

只需要确保首先设置下载的目标文件夹(我不知道如何通过批处理文件/脚本执行此操作)。该命令来自某人在位于此处的github上编写的脚本

  1. 运行 powershell 脚本以在最高设置下关闭隐私设置。这是通过以下命令完成的,同样来自上面的链接:

    .Set-Privacy.ps1 -Strong -admin
    
  2. 删除
  3. 后台应用程序,例如,删除"3D 生成器":

要卸载 3D 生成器:

get-appxpackage *3dbuilder* | remove-appxpackage

有关此内容的详细信息,请点击此处

非常感谢任何这方面的帮助。

试试这个,当然PowerShell本身不是一个批处理文件工具,尽管你可以使用它来调用批处理(.bat,.cmd.vbs等)文件。

虽然脚本是脚本(批处理或其他),但分类是一个完全不同的对话。

因此,您想要的是一个可以根据需要调用的函数。

Function Set-Windows10PrivacySettings
                          {
[CmdletBinding()]
[Alias()]
Param
(
[string]$DownloadPath = "$env:USERPROFILEDownloads"
)
# Download the Privacy Script
(New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/hahndorf/Set-Privacy/master/Set-Privacy.ps1') | 
out-file "$env:USERPROFILEDownloadsSet-Privacy.ps1"
# Temporarialy naviagte to the target directory adn run the script
Push-Location -Path $DownloadPath
Start-Process .Set-Privacy.ps1 -Strong -admin
# Remove AppX packages
$AppPackageList = (Get-AppxPackage).Name | 
Sort-Object | 
Out-GridView -Title 'Select one or more AppX to remove. Press CRTL+LeftMouseClick to multi-select' -PassThru
# Remove the selected AppX without prompt to confirm
ForEach($AppPackage in $AppPackageList)
{
"Removing selected AppX $AppPackage"
# Remove-AppxPackage -Package $_ -Confirm:$false -WhatIf
}
# Retrun to the original directory
Pop-Location
}
# Call the function in PowerShell
Set-Windows10PrivacySettings

只需删除注释标记"#"和"WhatIf"开关即可实际允许事情发生。

相关内容

最新更新