Powershell remote Session: UnauthorizedAccessException
Hi,
Ich möchte ein Powershell Script auf einem anderen PC ausführen.
Führe ich den Scriptblock local auf dem Zeil PC aus läuft alles.
Mach ich das per PSSession kommt ein Fehler.
Script das ausgeführt werden soll:
Der Remote Aufruf:
Die Ausgabe:
Der User "ALLE" ist local in der Gruppe Remoteverwaltung.
Mehr Lösungsansätze habe ich beim googlen auch nicht gefunden. habe ihr ne Idee?
Danke.
Ich möchte ein Powershell Script auf einem anderen PC ausführen.
Führe ich den Scriptblock local auf dem Zeil PC aus läuft alles.
Mach ich das per PSSession kommt ein Fehler.
Script das ausgeführt werden soll:
param (
[STRING]$mac_input = 'AA-BB-CC-11-22-33'
)
function WakUp{
[CmdletBinding()]
Param( [Parameter(Mandatory=$True)][STRING]$mac = 'AA-BB-CC-11-22-33')
[System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | Where-Object { $_.NetworkInterfaceType -ne [System.Net.NetworkInformation.NetworkInterfaceType]::Loopback -and $_.OperationalStatus -eq [System.Net.NetworkInformation.OperationalStatus]::Up } | ForEach-Object {
$networkInterface = $_
$localIpAddress = ($networkInterface.GetIPProperties().UnicastAddresses | Where-Object { $_.Address.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetwork })[0].Address
$targetPhysicalAddress = [System.Net.NetworkInformation.PhysicalAddress]::Parse(($mac.ToUpper() -replace '[^0-9A-F]',''))
$targetPhysicalAddress
$targetPhysicalAddressBytes = $targetPhysicalAddress.GetAddressBytes()
$packet = [byte[]](,0xFF * 102)
6..101 | Foreach-Object { $packet[$_] = $targetPhysicalAddressBytes[($_ % 6)] }
$localEndpoint = [System.Net.IPEndPoint]::new($localIpAddress, 0)
$targetEndpoint = [System.Net.IPEndPoint]::new([System.Net.IPAddress]::Broadcast, 9)
$client = [System.Net.Sockets.UdpClient]::new($localEndpoint)
try { $client.Send($packet, $packet.Length, $targetEndpoint) | Out-Null } finally { $client.Dispose() }
}
}
If ($MyInvocation.Line[0] -ne "."){
WakUp -mac $mac_input
}
Der Remote Aufruf:
$pwd = ".\Invoke.pw"
#User-Objekt erstellen
$cred = New-Object -TypeName System.Management.Automation.PSCredential "Domain\Alle", (Get-Content $pwd | ConvertTo-SecureString)
# Befehle für Remote PC erstellen
$mac = 'AA-BB-CC-11-22-33'
$InvScript = {\\server01\WOL_Script.ps1 -mac $mac |Out-File -FilePath "C:\Temp\PS_LOG.txt"}
# Befehl auf anderem PC ausführen
$PSs = New-PSSession -ComputerName Prakt-01 -Credential $cred
Write-Host "hallo"
Invoke-Command -Session $PSs -ScriptBlock $InvScript
Die Ausgabe:
hallo
Zugriff verweigert
+ CategoryInfo : OperationStopped: (:) [], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException
+ PSComputerName : Prakt-01
Der User "ALLE" ist local in der Gruppe Remoteverwaltung.
Mehr Lösungsansätze habe ich beim googlen auch nicht gefunden. habe ihr ne Idee?
Danke.
Please also mark the comments that contributed to the solution of the article
Content-Key: 21955491327
Url: https://administrator.de/contentid/21955491327
Printed on: April 28, 2024 at 15:04 o'clock
3 Comments
Latest comment
Hi.
Ich bin kein Freund von PSRemoting, aber dazu später.
Bist Du sicher, dass die Gruppenmitgliedschaft reicht?
Funktioniert der Befehl als Mitglied der Admingruppe (Admingruppe auf dem Remotesystem)?
Ich führe Befehle remote als "immediate scheduled task", der als Executor das Systemkonto ("System") nutzt, aus. Somit erspare ich mir jegliche mit psremoting verbundenen Sicherheitsrisken.
Ich bin kein Freund von PSRemoting, aber dazu später.
Bist Du sicher, dass die Gruppenmitgliedschaft reicht?
Funktioniert der Befehl als Mitglied der Admingruppe (Admingruppe auf dem Remotesystem)?
Ich führe Befehle remote als "immediate scheduled task", der als Executor das Systemkonto ("System") nutzt, aus. Somit erspare ich mir jegliche mit psremoting verbundenen Sicherheitsrisken.
Series: Powershell
Powershell: Office Programme inkl.- Bit-Version Auslesen (german)2W11: Aufgabenplanung führt PS Copy-item nicht aus (german)3Powershell remote Session: UnauthorizedAccessException (german)3Powershell eigenes Objekt in Funktion verändern (german)2Powershell individueller Rückgabewert von AddClick (german)7Aufgabenplanung: Powershell Script im Hintergrund mit Userbenachrichtigung im Vordergrund (german)Powershell: Aufgabe im Hintergrund MsgBox in Vordergrund (german)25