Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- $computername = "<zielcomputer>",
- $username = "<domain>\<username>",
- $password = '<passwort>',
- $command = "<kommando inkl. parametern>"
- )
- Import-Module @("Microsoft.PowerShell.Management","PSDiagnostics");
- try{
- # Generate credentials object for authentication
- $SecPasswd = ConvertTo-SecureString $password -AsPlainText -Force
- $Credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
- Invoke-Command -ComputerName $computername -ScriptBlock { param($command) Invoke-Expression $command } -ArgumentList @($command) -Credential ($Credentials) }
- catch
- { throw [System.IO.FileNotFoundException] "The command could not be executed on the remote host"; exit 2 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement