简体   繁体   English

来自TFS发行版自动化的IIS管理-PowerShell脚本无法通过Get-ChildItem -Path IIS:\\ Sites

[英]IIS Administration from TFS Release automation - PowerShell script fails Get-ChildItem -Path IIS:\Sites

I'm having difficulty in using the Powershell WebAdministration Module with Powershell 5.1. 我在将Powershell WebAdministration模块与Powershell 5.1结合使用时遇到困难。

This is on a Server 2008R2 machine, running IIS 7.5 这是在运行IIS 7.5的Server 2008R2计算机上

There seems to be an issue with this module in that occasionally the module requires a few ms to complete initialization after loading. 该模块似乎存在问题,因为该模块有时在加载后需要几毫秒才能完成初始化。 The recommendation is to do a simple 'write-output' after loading to allow the server to complete the init tasks. 建议在加载后执行简单的“写输出”,以允许服务器完成初始化任务。 I dont see it on all the servers I'm managing, but this particular server is consistent in its need. 我在所管理的所有服务器上都没有看到它,但是此特定服务器的需求是一致的。

There's also an issue that I found people had with Get-Sites failing that could be dealt with by wrapping in a try/catch. 我发现还有一个问题,就是人们遇到Get-Sites失败的情况,可以通过包装try / catch来解决。

However, the problem I'm seeing is that even with the identified workarounds, I'm not getting consistent results between an interactive run, and a run that is performed from TFS Automated release. 但是,我看到的问题是,即使有了确定的解决方法,我也无法在交互式运行和从TFS自动版本执行的运行之间获得一致的结果。

Import-Module WebAdministration
$sites="none"
Write-Output "suggested as a work around for the task dying for no apparent reason"
try {
    $sites = Get-ChildItem -Path IIS:\Sites
    Write-Output "part of try"
} catch {
    $sites = Get-ChildItem -Path IIS:\Sites
    Write-Output "part of catch"
} finally {
    Write-Output  $sites
    Write-Output  $sites.GetType()
}

When run via TFS Release automation (agent version 2.117.2, PowerShell on the target machine version 1.0.47): 通过TFS Release Automation(代理程序版本2.117.2,在目标计算机版本1.0.47上运行PowerShell)运行时:

 2018-01-25T13:18:29.5474995Z Importing alias 'End-WebCommitDelay'.
 2018-01-25T13:18:29.5474995Z 
 2018-01-25T13:18:29.5474995Z suggested as a work around for the task dying for no apparent reason
 2018-01-25T13:18:29.5474995Z part of catch
 2018-01-25T13:18:29.5474995Z 
 2018-01-25T13:18:29.5474995Z 
 2018-01-25T13:18:29.5631000Z Deployment status for machine 'DESTSERV:5985' : 'Passed'

(no sitelist is returned) (没有返回站点列表)

When run as an interactive process (with same user) 当以交互过程运行(与同一用户)

PS C:\Users\Install> C:\Installers\Modules\test-iis.ps1
suggested as a work around for the task dying for no apparent reason
part of try

Name             ID   State      Physical Path                  Bindings
----             --   -----      -------------                  --------
AppTest          2    Started    E:\WebApps\AppTest             http *:80:
                                                                https *:443:
Test             1    Stopped    C:\inetpub\wwwroot\Test        http *:80:
                                                                https 



Module                     : CommonLanguageRuntimeLibrary
Assembly                   : mscorlib, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089
TypeHandle                 : System.RuntimeTypeHandle
DeclaringMethod            :
BaseType                   : System.Array
UnderlyingSystemType       : System.Object[]
FullName                   : System.Object[]
AssemblyQualifiedName      : System.Object[], mscorlib, Version=4.0.0.0, 
Culture=neutral,
                             PublicKeyToken=b77a5c561934e089
Namespace                  : System
GUID                       : 00000000-0000-0000-0000-000000000000
IsEnum                     : False
GenericParameterAttributes :
IsSecurityCritical         : False
IsSecuritySafeCritical     : False
IsSecurityTransparent      : True
IsGenericTypeDefinition    : False
IsGenericParameter         : False
GenericParameterPosition   :
IsGenericType              : False
IsConstructedGenericType   : False
ContainsGenericParameters  : False
StructLayoutAttribute      :
Name                       : Object[]
MemberType                 : TypeInfo
DeclaringType              :
ReflectedType              :
MetadataToken              : 33554432
GenericTypeParameters      : {}
DeclaredConstructors       : {Void .ctor(Int32)}
DeclaredEvents             : {}
DeclaredFields             : {}
DeclaredMembers            : {Void Set(Int32, System.Object), System.Object& 
Address(Int32), System.Object Get(Int32),
                             Void .ctor(Int32)}
DeclaredMethods            : {Void Set(Int32, System.Object), System.Object& 
Address(Int32), System.Object Get(Int32)}
DeclaredNestedTypes        : {}
DeclaredProperties         : {}
ImplementedInterfaces      : {System.ICloneable, System.Collections.IList, 
System.Collections.ICollection,
                             System.Collections.IEnumerable...}
TypeInitializer            :
IsNested                   : False
Attributes                 : AutoLayout, AnsiClass, Class, Public, Sealed, 
Serializable
IsVisible                  : True
IsNotPublic                : False
IsPublic                   : True
IsNestedPublic             : False
IsNestedPrivate            : False
IsNestedFamily             : False
IsNestedAssembly           : False
IsNestedFamANDAssem        : False
IsNestedFamORAssem         : False
IsAutoLayout               : True
IsLayoutSequential         : False
IsExplicitLayout           : False
IsClass                    : True
IsInterface                : False
IsValueType                : False
IsAbstract                 : False
IsSealed                   : True
IsSpecialName              : False
IsImport                   : False
IsSerializable             : True
IsAnsiClass                : True
IsUnicodeClass             : False
IsAutoClass                : False
IsArray                    : True
IsByRef                    : False
IsPointer                  : False
IsPrimitive                : False
IsCOMObject                : False
HasElementType             : True
IsContextful               : False
IsMarshalByRef             : False
GenericTypeArguments       : {}
CustomAttributes           : {[System.SerializableAttribute()]}


PS C:\Users\Install>

When WebAdministration doesn't import properly it seems there is more going wrong than just a slow initialization. 如果WebAdministration无法正确导入,则似乎出错的不仅仅是缓慢的初始化。 The IIS: provider is not functional.. it throws no error. IIS:提供程序不起作用..它不会引发任何错误。 It does return something though - the value set at the top of the script is being overwritten... I just dont get the sites list. 它确实会返回一些信息-脚本顶部设置的值被覆盖...我只是没有得到站点列表。

As can be seen by the interactive run, there are sites present, so an empty return value does not make any sense. 从交互式运行可以看出,存在站点,因此空的返回值没有任何意义。

Updated: 更新:

All the suggested workarounds have been applied yet the Get-ChildItem in the catch fails to produce the sites list. 所有建议的解决方法都已应用,但是捕获中的Get-ChildItem无法生成站点列表。 How do I get a consistent result where I can obtain the full list of sites in IIS both interactively and through TFS Release's PowerShell on the target machine task?? 我如何获得一致的结果,以便可以在目标机器任务上以交互方式以及通过TFS发行版的PowerShell获得IIS中站点的完整列表?

I can run the script via TFS Release automation without any error and get the consistent result with the interactive process. 我可以通过TFS发行版自动化运行脚本,而不会出现任何错误,并且可以通过交互式过程获得一致的结果。 (Agent version 2.117.1 , PowerShell on the target machine version 5.1.14393.1944 ). (代理程序版本2.117.1 ,目标计算机版本5.1.14393.1944上的PowerShell)。

You need to set the TFS build agent service account as an local administrator account in the target machine (Just add the build agent service account to the local administrators group). 您需要将TFS build agent service account为目标计算机中的本地管理员帐户(只需将build agent service account添加到本地administrators组)。

So, please have a try with that. 因此,请尝试一下。 If that still not work, just try to upgrade the PowerShell version on your target machine (may be caused by the PS version). 如果仍然无法解决问题,请尝试在目标计算机上升级PowerShell版本(可能是PS版本引起的)。 Refer to Install PowerShell 5 in Windows Server 2008 R2 for details. 有关详细信息,请参考在Windows Server 2008 R2中安装PowerShell 5

在此处输入图片说明


UPDATE: 更新:

Generally, the output of the scripts will not back to build process when run the PS scripts with task PowerShell on the target machines . 通常, PowerShell on the target machines使用任务PowerShell on the target machines运行PS脚本时,脚本的输出不会返回到构建过程。

You need to update the script to get back the outputs (use Write-Verbose instead of Write-Output ), just try below scripts, it works for me: 您需要更新脚本以获取输出(使用Write-Verbose而不是Write-Output ),只需尝试以下脚本,它就对我有用:

Import-Module WebAdministration
$sites="none"
Write-Verbose "suggested as a work around for the task dying for no apparent reason"
try {
    $sites = Get-ChildItem -Path IIS:\Sites | Out-String
    Write-Verbose "part of try"
} catch {
    $sites = Get-ChildItem -Path IIS:\Sites | Out-String
    Write-Verbose "part of catch"
} finally {
    Write-Verbose  $sites -verbose
    Write-Verbose  $sites.GetType() -verbose
}

在此处输入图片说明

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

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