I'm working on a script to create scan folder shortcut on PC (target folder on server) , but PC more than 1000+. The following script works fine as one by one, I would like to increase efficiency and shorten the time. Is there any way I could Invoke-Command them in the same time in a parallel? An example would be appreciated. Thanks
Invoke-Command -ComputerName 'PC001','PC002' -ScriptBlock { Register-PSSessionConfiguration -RunAsCredential 'domain\user' -Name test -Force }
Invoke-Command -ComputerName 'PC001','PC002' -FilePath 'C:\temp\create scan shortcut.ps1' -ConfigurationName test
#get server name and pc name
$PCname = $env:computername
$Servername = $PCname.Substring(0,9)+"P001"
#create shortcut on C:\
$SourceFileLocation = "\\$Servername\Scan"
$ShortcutLocation = "C:\Scan.lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
$Shortcut.Save()
#test path
$path = Test-Path -path "C:\Scan.Lnk"
if ($path -eq 'True'){
Write-Host "$PCname Scan folder already existed" -ForegroundColor Green
}
else{
Write-Host "$PCname Scan folder does not exist" -ForegroundColor Red
}