S
S
shell_guy2021-09-03 10:42:29
PowerShell
shell_guy, 2021-09-03 10:42:29

How to copy a folder via smb only to turned on computers?

I found sample scripts on the net. Enabled WinRM via logon script.
When I try to copy over a network share from a domain controller through a powershell script, I get an error:

$computername = (Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))" -Properties name | Sort).name;
$src = "\\DC-01\c$\zabbix\*"

foreach ($computer in $computername) 
{
    $df = "\\$computer\c$\zabbix"


    if (!(Test-Path -path $df))
    {
        New-Item $df -Type Directory
    }
    Copy-Item -Path $src  -Destination $df;
    Invoke-Command -ComputerName $computer -ScriptBlock {powershell "& 'C:\zabbix\install.bat'"}


[WS-01_MELNIK] Failed to connect to remote server WS-01_MELNIK. Error message: The WinRM client could not process the request because the server name could not be resolved. See help section for details.
"about_Remote_Troubleshooting".
    + CategoryInfo          : OpenError: (WS-01_MELNIK:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : ComputerNotFound,PSSessionStateBroken
New-Item : Не найден сетевой путь
At line:13 char:9
+         New-Item $destinationFolder -Type Directory
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-Item], IOException
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemCommand


How to copy a folder ONLY to turned on PCs?
And yet, PC DNS names are truncated, how to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir, 2021-09-03
@FluffyBeaver

If you answer based on the question - you can check the availability of the node using Test-NetConnection .
The rest of the things (DNS names are truncated - what is it about? Where?) It is better to discuss in the comments.

R
Roman Bezrukov, 2021-09-03
@NortheR73

Is it not an option to install the zabbix agent through GPO?
PS what will the script do if the computer is turned on and the agent is already installed?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question