sof*_*fun 3 windows powershell windows-xp powershell-2.0 windows-7
我写了一个脚本将文件复制到“所有用户”桌面或“公共桌面”
但是,我们有一个混合的环境。有些人使用Windows XP,而其他人使用Windows 7。
$SOURCE = "I:\Path\To\Folder\*"
$DESTINATION7 = "c$\Users\Public\Desktop"
$DESTINATIONXP = "c$\Documents and Settings\All Users\Desktop"
$computerlist = Get-Content I:\Path\To\File\computer-list.csv
$results = @()
$filenotthere = @()
$filesremoved = @()
foreach ($computer in $computerlist) {
if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{
Write-Host "\\$computer\$DESTINATION\"
Copy-Item $SOURCE "\\$computer\$DESTINATION\" -Recurse -force
} else {
$details = @{
Date = get-date
ComputerName = $Computer
Destination = $Destination
}
$results += New-Object PSObject -Property $details
$results | export-csv -Path I:\Path\To\logs\offline.txt -NoTypeInformation -Append
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
目的地为空。扩展Keith的建议:
foreach ($computer in $computerlist) {
if((Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{
$OS = Get-WmiObject -Computer $computer -Class Win32_OperatingSystem
if($OS.caption -like '*Windows 7*'){
$DESTINATION = $DESTINATION7
}
if($OS.caption -like '*Windows XP*'){
$DESTINATION = $DESTINATIONXP
}
}
}
Run Code Online (Sandbox Code Playgroud)
这样可以避免出现错误。empty $DESTINATION。
| 归档时间: |
|
| 查看次数: |
52414 次 |
| 最近记录: |