移动桌面项目

Move Desktop Items

我的代码需要一些帮助。 我目前在 Citrix 环境中工作,并保持 运行ning 在第 4 行的墙上。 我已经尝试过创建和不创建名为 desktopicons 的变量。

当我 运行 前 3 行时,似乎所有代码都运行良好,直到第四行。

PS 脚本的主要思想是创建一个新文件夹,将所有桌面图标移动到这个新创建的文件夹中。

mkdir -Name "newfolder" -Path "C:\Users\%username%\Desktop\" -Force

Get-Process "C:\Users\%username%\Desktop\*" |   Foreach-Object { $_.CloseMainWindow() | Out-Null } | stop-process

$desktopicons="$Env: C:\Users\%username%\Desktop"

Move-Item -Exclude "$desktopicons\newfolder" -Path "$desktopicons*" -Destination "$desktopicons\newfolder\" -Force

我认为您将批处理文件搞混了。这是我的方法:

#get desktop path for current user
$DesktopPath = $ENV:HOMEDRIVE+$ENV:HOMEPATH+"\Desktop"

#create "newfolder" on users desktop
New-Item -Path $DesktopPath -Name 'newfolder' -Type Directory    

#move all files from desktop into "newfolder" excluding "newfolder"
Move-Item -Path $DesktopPath"\*" -Destination $DesktopPath"\newfolder" -exclude 'newfolder' -WhatIf

我添加了参数 -WhatIf 来查看 to line 实际做了什么(而不是仅仅这样做)。如果你得到的输出对你来说没问题,你只需要删除这个参数来执行任务。