因此,我正在运行一个基本脚本来将快捷方式复制到公共配置文件桌面,以便任何登录的用户都可以在其桌面上看到该快捷方式。情况是我将不得不绕过执行策略,所以我通过批处理文件来做到这一点。这是我尝试过的,但似乎对我不起作用......
Powershell.exe -Command "& {Start-Process Powershell.exe -ArgumentList 'ExecutionPolicy Bypass -File DesktopShortcut.ps1' -Verb RunAs}"
Run Code Online (Sandbox Code Playgroud)
PS文件很简单:
Copy-Item -Path "aiStarter.lnk" -Destination "C:\Users\Public\Desktop\" -PassThru
Run Code Online (Sandbox Code Playgroud)
当我运行它时,窗口只是闪烁然后消失。如果我在没有 RunAs 的情况下运行它,我会拒绝访问。我不想问这个,因为我确定以前有人问过这个问题,但我很确定我正确地执行了这个问题。想法?
我在这里有一个哈希表,我最终输出到Excel电子表格,但问题似乎是系统默认情况下对哈希表进行排序的方式.我希望它以与它们输入相同的顺序返回机器,它们当前工作的方式是弹出一个框并粘贴所有机器名称,以便它们在foreach循环之前都在内存中.我之前通过最长的正常运行时间对它进行排序,但它现在需要与它们输入的方式相同.我最初的想法是创建另一个哈希表并以与$machineList变量相同的顺序捕获它们,但这甚至可能使我处于相同的位置.我试图搜索,但我找不到哈希表排序的默认方式的信息.
有任何想法吗?
$machineUptime = @{}
foreach($machine in $machineList){
if(Test-Connection $machine -Count 1 -Quiet){
try{
$logonUser = #gets the logged on user
$systemUptime = #gets the wmi property for uptime
if($logonUser -eq $null){
$logonUser = "No Users Logged on"
}
$machineUptime[$machine] = "$systemUptime - $logonUser"
}
catch{
Write-Error $_
$machineUptime[$machine] = "Error retrieving uptime"
}
}
else{
$machineUptime[$machine] = "Offline"
}
}
Run Code Online (Sandbox Code Playgroud)