[英]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.