我当前有此脚本工作,但只能使其在本地运行,我想让它读取将存储在C: List_of_pcs.txt上的文本文件具有也将在同一脚本上运行的计算机名称。这样,我可以更新文本文件而不是修改代码。
Set-ExecutionPolicy RemoteSigned
# Get all users
$users = Get-ChildItem -Path "C:Users"
# Loop through users and delete the Teams file
$users | ForEach-Object {
Remove-Item -Path "C:Users$($_.Name)AppDataRoamingMicrosoftTeamsCachef*" -Force
Remove-Item -Path "C:Users$($_.Name)AppDataRoamingMicrosoftTeamsApplication CacheCachef*" -Force
}
在此方面的任何帮助,我都尝试了多种事情,我敢肯定这很简单,但是我对Powershell仍然非常新。
尝试这样的东西...
需要启用powershell远程驱动器,并使用远程计算机上的admin的帐户
$ComputerList = Import-Csv -Path 'c:List_of_PCs.txt'
$ComputerList | % {
Invoke-Command -ComputerName $_ -ScriptBlock {
# Set-ExecutionPolicy RemoteSigned # this is something that should be set via GPO for all systems, not your script, so that it is centrally controlled and monitored.
# Get all users
$users = Get-ChildItem -Path "C:Users"
# Loop through users and delete the Teams file
$users | ForEach-Object {
Remove-Item -Path "C:Users$($_.Name)AppDataRoamingMicrosoftTeamsCachef*" -Force
Remove-Item -Path "C:Users$($_.Name)AppDataRoamingMicrosoftTeamsApplication CacheCachef*" -Force
}
}
}