与其他用户一起运行PowerShell Invoke命令

与其他用户一起运行PowerShell Invoke命令,powershell,Powershell,我对此Powershell命令有问题: #var1 $Username = 'rdv\miguser' $pass = ConvertTo-SecureString -AsPlainText abcde -Force $Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass invoke-command -computername target -scriptb

我对此Powershell命令有问题:

#var1
$Username = 'rdv\miguser'
$pass = ConvertTo-SecureString -AsPlainText abcde -Force
$Credential = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
invoke-command -computername target -scriptblock {mkdir E:\BambooScripts\prod\test4} -Credential $Credential


Enable-PSRemoting


#var2
#Variables to store the username and password for the alternate account            
$SPFarmAccountName = "rdv\myuser";            
$SPFarmAccountName = "myuser";            
$FarmAccountPassword = "mypwd";            

#Convert the plain text password to a SecureString, required to create the PSCredential object
$FarmAccountPasswordAsSecureString = $FarmAccountPassword | ConvertTo-SecureString -Force -AsPlainText            

#Create the PSCredential object using the alternate users username and password            
#Note that the Domain name has been prepended to the username, using the $env:userdomain variable, which represents the current domain.            
$credential = New-Object System.Management.Automation.PsCredential("$env:userdomain\$SPFarmAccountName",$FarmAccountPasswordAsSecureString)              

#Create a new PowerShell session in the security context of the alternate user, using the PSCredential object we just created            
$farmSvcAccSession = New-PSSession -Credential $credential -computername target ;            

#Pass the PSSession object to Invoke-Command, and write some text to the PowerShell Window, that prints the username from the current context of the PSSession object (which will be the security context of the alternate user)            
Invoke-Command -computername target -Session $farmSvcAccSession -Script { mkdir E:\BambooScripts\prod\test7 }            

Invoke-Command -Session $farmSvcAccSession -Script { mkdir E:\BambooScripts\prod\test7 }      
此代码创建测试文件夹。但是,本地管理员被设置为所有者。因此,我以后会遇到授权问题。 有人能帮忙吗

干杯 福克