2
I have the following code snippet:
foreach($File in $(Get-ChildItem -Path $FromPath)){ $ObjFolder.CopyHere($File.fullname, $CopyOptions); }
it copies the files to the windows folder, however users are not allowed to do this, I am trying to use the following excerpt:
Invoke-Command -ScriptBlock $script -Credential contoso\admin;
but it’s not working, you’d have to save your credentials in a variable, so that it doesn’t ask permission for every file that you copy?
full script:
function getCredencial(){ $usario = Read-Host "Usuario" $senha = Read-Host -AsSecureString "Senha" return New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $usario, $senha } $script = { $FONTS = 0x14; $FromPath = "\\servidor01\arquivos\fontes\"; $ObjShell = New-Object -ComObject Shell.Application; $ObjFolder = $ObjShell.Namespace($FONTS); $CopyOptions = 4 + 16; $CopyFlag = [String]::Format("{0:x}", $CopyOptions); foreach($File in $(Get-ChildItem -Path $FromPath)){ $ObjFolder.CopyHere($File.fullname, $CopyOptions); } } $credenciais = getCredencial; Invoke-Command -ScriptBlock $script -Credential $credenciais;
tested this solution, but is giving the following error:
Invoke-Command: O Conjunto de parâmetros não pode ser resolvido usando os parâmetros nomeados especificados.
– MeuChapeu
@Meuchapeu, the content of
$script
is the foreach? which version of the powershell is using?– rray
edited the question, put the script as it is now.
– MeuChapeu
@Meuchapeu, in
invoke-command
add the argument-ComputerName $env:COMPUTERNAME
that passes the name of the machine.– rray
thank you, it worked!
– MeuChapeu