Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 从rundeck(linux)运行powershell会显示不同的结果_Bash_Powershell_Rundeck - Fatal编程技术网

Bash 从rundeck(linux)运行powershell会显示不同的结果

Bash 从rundeck(linux)运行powershell会显示不同的结果,bash,powershell,rundeck,Bash,Powershell,Rundeck,我正在尝试从rundeck(linux)运行powershell脚本,如果我在本地运行该脚本[从多个终端服务器删除一些文件](Windows服务器),它将按预期工作,但是如果我从rundeck服务器(winrm配置)调用它,则该脚本似乎无法访问我尝试访问的远程文件夹 我尝试使用相同的用户运行脚本,但仍然显示不同的结果 下面的脚本: $userAD = "someuser" $servers = Get-Content C:\TSList.csv $Folder = "

我正在尝试从rundeck(linux)运行powershell脚本,如果我在本地运行该脚本[从多个终端服务器删除一些文件](Windows服务器),它将按预期工作,但是如果我从rundeck服务器(winrm配置)调用它,则该脚本似乎无法访问我尝试访问的远程文件夹

我尝试使用相同的用户运行脚本,但仍然显示不同的结果

下面的脚本:

$userAD = "someuser"
$servers = Get-Content C:\TSList.csv
$Folder = "c$\Users\$userAD\"
$TSFolderShare = "\\sharepath"

Write-Output "#####Start of script#####"
Write-output `n
Write-output "Checking if $userAD user profile exist in Terminal servers..."

sleep -seconds 1

foreach ($server in $servers) {

Test-Path "\\$server\$Folder" -PathType Any
Get-ChildItem "\\$server\$Folder" 

    if (Test-Path "\\$server\$Folder" -PathType Any) {
        Write-output  "Resetting user profile in $server.."
                   Get-ChildItem "\\$server\$Folder" -Recurse -Force -ErrorAction SilentlyContinue  | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue 
        
        sleep -seconds 1
        Write-output "Done." 

        if( (Get-ChildItem "\\$server\$Folder" | Measure-Object).Count -eq 0)
             {
                Write-output "Done." 
             }
        
    }
    else
    {
        Write-output  "Resetting user profile in $server.."
        sleep -seconds 1
        Write-output  "User profile does not exist in $server."          
        #Write-output "\\$server\$Folder does not exist in $server!" -ForegroundColor Red
    }
}

编辑:我的问题似乎是从另一个带有RunAS的脚本运行脚本

下面我尝试使用ps脚本从另一台服务器访问一个文件夹,但由于我想将其集成到Rundeck,所以需要使用python从linux服务器调用ps脚本。我做了一个测试,直接运行ps脚本,并使用另一个脚本调用测试路径脚本,其中RunUs使用的用户与我手动运行脚本时使用的用户相同

  • 情景1 通过单独的PS脚本和RunAS(我的帐户)运行PS脚本

    $username=“我的账户” $password=“我的密码” $secstr=新对象-TypeName System.Security.SecureString $password.ToCharArray()| ForEach对象{$secstr.AppendChar($|)} $cred=新对象-typename System.Management.Automation.PSCredential-argumentlist$username,$secstr

    调用命令-FilePath“C:\testpath.ps1”-凭证$cred-计算机本地主机

  • (C:\testpath.ps1)内容如下:

    测试路径“\\server\c$\Users\myaccount\”

    结果:

    访问被拒绝 +CategoryInfo:PermissionDenied:(\server\c$\Users\myaccount:String)[测试路径],UnauthorizedAccessException +FullyQualifiedErrorId:ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand +PSComputerName:localhost

    假的

  • 情景2 直接作为我的\u帐户运行C:\testpath.ps1
  • 测试路径“\\server\c$\Users\myaccount\”

    结果:
    正确

    解释说,您正面临Rundeck和Powershell的双跳问题。这是以前问过的问题,看一看,这是一个很好的解决方法。也是为了解决这个问题。

    我在powershell中使用了会话配置来解决这个问题。通过这种方式,您可以将凭据绑定到PowerShell会话配置,并将此配置重新用于将来的所有连接


    非常感谢

    嗨,当脚本从Rundeck执行时,您看到了什么消息?你能分享一下吗?(请更改或隐藏任何敏感信息)。当做你能分享你的工作定义来检查脚本是如何定义的吗?还要查看您的windows节点定义(resources.xml)。谢谢MegaDrive68k 37分钟前您好,感谢您的回复我更新了帖子,基本上我的原始脚本将从另一个终端服务器删除目录内容,如果我手动运行脚本(通过ISE或./),它将正常工作。但是,如果我使用另一个脚本调用脚本,并且我尝试访问的路径被拒绝,我还定义使用与手动运行时使用的相同的用户。非常感谢。