繁体   English   中英

RemotePSSession中的Chng执行策略

[英]Chng Execution Policy in RemotePSSession

我正在尝试写一些提示输入PC名称的内容,然后远程执行文件夹权限更改。 一切看上去都很混乱,但是在Enter-PSSession之后,我正在努力更改执行策略-似乎只是卡住了,将无法继续进行我的功能。

这是我到目前为止的粗略草稿。 任何帮助表示赞赏。

$PromptedPC = Read-Host -Prompt "`n `n Enter PC Number" 
Enter-PSSession -ComputerName $PromptedPC


Write-Host `n"Do you want to change folder permissions?" -ForegroundColor Green
$ReadAnswer = Read-Host " ( y / n ) "
PowerShell.exe -noprofile -ExecutionPolicy Bypass

switch ($ReadAnswer)
    { 
      Y {

function Grant-userFullRights {            
 [cmdletbinding()]            
 param(            
 [Parameter(Mandatory=$true)]            
 [string[]]$Files,            
 [Parameter(Mandatory=$true)]            
 [string]$UserName            
 )            
 $rule=new-object System.Security.AccessControl.FileSystemAccessRule ($UserName,"FullControl","Allow")            

 foreach($File in $Files) {            
  if(Test-Path $File) {            
   try {            
    $acl = Get-ACL -Path $File -ErrorAction stop            
    $acl.SetAccessRule($rule)            
    Set-ACL -Path $File -ACLObject $acl -ErrorAction stop            
    Write-Host "Successfully set permissions on $File"            
   } catch {            
    Write-Warning "$File : Failed to set perms. Details : $_"          
    Continue            
   }            
  } else {            
   Write-Warning "$File : No such file found"           
   Continue            
  }            
 }            
}
}
}
Grant-userFullRights -Files 'C:\ProgramData\New World Systems\' -UserName "BUILTIN\Users"

我确实从以下网站获得了功能信息: http : //techibee.com/powershell/grant-fullcontrol-permission-to-usergroup-on-filefolder-using-powershell/2158

我只是想将一些东西组合在一起,以适合programdata文件夹,而我们的用户需要对此进行完全控制,以便将权限还原为比完全访问权限低的权限。

您可以使用ExecutionPolicy Bypass启动新的PowerShell。

既然您已经在PowerShell中,则配置执行策略的正确方法是Set-ExecutionPolicy

但是,由于您不调用任何脚本文件,因此无需更改执行策略。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM