Tell me, please, what's the problem?
I wrote a simple PS script that pings the site, in case of a non-response, reloads the network adapter and sends a message to the computers from the list using msg . But, for some reason, a separate function that sends messages, when called, works normally, and when called, the condition gives an error:
Ошибка 1722 при получении имени сеанса C:\Users\username\Desktop\PS\CheckInternet.ps1:22 знак:6 + msg $Session /Server:$Recepient $Message + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Ошибка 1722 при получении имени сеанса:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError The code itself:
$Site = "ya.ru" $ListRecepients = Get-Content "C:\Scripts\recepients.txt" $Session = "*" $Message = "Доступ в интернет отсутствует. Начинаю перезагрузку сетевого адаптера" function PingSite { if ((Test-Connection -CN $Site -Count 1 -BufferSize 16 -Quiet) -match 'True') { write-host -ForegroundColor green Done } else { write-host -ForegroundColor red Undone WTF Restart-NetAdapter -Name "Ethernet" } } function WTF { ForEach ($Recepient in $ListRecepients) { msg $Session /Server:$Recepient $Message } } Moreover, googling, even corrected the key AllowRPC in the registry, but the result is the same.
msg $Session /Server:$Recepient $Message 2> $null- Senior Pomidor