Netzwerk-Ordner anlegen

  • Erzeuge mit Windows Explorer einen Ordner namens network-share (der Einfachheit halber direkt unter C:\) und lege eine Datei example.txt darin an.
  • Starte cmd als admin.

NET SHARE ourNetworkShare=C:\network-share /GRANT:everyone,FULL

  • Schaue in Ordnereigenschaften unter Sharing – dort findet sich der Network Path
  • Exakt diesen Network Path gibst Du im Windows Explorer auf einem anderen Computer (in der gleichen Domain ein!)

Die example.txt ist jetzt sowohl von Hostordner, als auch vom Netzwerk-Ordner aus erreichbar:

PowerShell: Ausführen eines Commands auf einem remote Rechner mit einem anderen User

Grundlage folgenden Skripts findet sich hier.

$remoteAccountCredential = get-credential #fill your credential in the pop-up window;

Write-Host "This PowerShell command is running under the current users context: $env:userdomain\$env:username" -f Red;

Invoke-Command -ComputerName -ScriptBlock {

Write-Host "Hello, this script block is running under the security context of the remote account: $env:userdomain\$env:username" -f Yellow;

NET USER alex alex /ADD;
# A Windows user needs certain permissions for a PowerShell-Session. Because I'm too lazy for creating a proper statement, I add the new user to the administrators group, which has permission for everything. At the end of that invoke command I'll delete the new user anyway:
NET LOCALGROUP administrators alex /ADD;

$innerAccountName = ".\alex";
$innerAccountPassword = "alex";
$innerAccountAsSecureString = $innerAccountPassword | ConvertTo-SecureString -Force -AsPlainText;
$innerAccountCredential = New-Object System.Management.Automation.PsCredential($innerAccountName,$innerAccountAsSecureString);
$innerAccountSession = New-PSSession -Credential $innerAccountCredential;

Invoke-Command -Session $innerAccountSession -Script {
Write-Host "Hello, this script block is running under the security context of the inner account: $env:userdomain\$env:username" -f Green;
};

NET USER alex /DELETE;

} -credential $remoteAccountCredential;

Write-Host "And now we return to the current users context: $env:userdomain\$env:username" -f Red;

PowerShell: User anlegen und Prozess mit diesem starten

NET USER michael "michael" /ADD
#net localgroup administrators michael /add

$username = 'michael'
$password = 'michael'

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process Notepad.exe -Credential $credential

Ergebnis: