我试图遍历域中的Windows计算机列表来调用磁盘清理,因为该列表的返回方式并不是使用替换的名称执行ForEach语句。有没有人能提供一些关于如何使其工作的指导?
Get-ADComputer -Filter {OperatingSystem -Like "*windows*"} -Property * | Format-Table Name | foreach {Echo "psexec \\$ cleanmgr /sagerun:1"}发布于 2016-07-27 07:06:54
我让它以我想要的方式工作,并与特定的OU一起工作。
ForEach ($COMPUTER in (Get-ADComputer -Filter * | Where-Object {$_.DistinguishedName -Like "*OU=Employee's Computers,DC=company,DC=com"} | Select-Object -ExpandProperty Name)) { .\psexec \\$COMPUTER cleanmgr /sagerun:1 }发布于 2016-07-27 06:27:22
像这样的东西
$computers = get-Content c:\computers.txt
foreach ($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {& \\$computer\C$\Windows\System32\cleanmgr.exe /sagerun:1}}https://stackoverflow.com/questions/38600687
复制相似问题