本文介绍了PowerShell命令缺少大会谷歌阿比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 只是想创建一个PowerShell命令时遇到的问题。我可以在一个控制台应用程序就好内的过程记录执行相同的代码。想法是在app.config没有进行重定向程序集,但并没有多少成功使其工作。我用的NuGet包引用到谷歌的API-dotnet的客户端 此示例代码 http://tinyurl.com/mbx3yle 错误 http://i.imgur.com/ xiEjwAR.png GET-GAppsUsers:无法加载文件或程序'System.Net.Http.Primitives,版本= 1.5.0.0,文化=中立,公钥= b03f5f7f11d50a3a'或它的一个依赖。该系统找不到指定的文件。 PsTest.cs 使用System.ComponentModel; 使用System.Collections.Generic; 使用Google.Apis.Admin.Directory.directory_v1.Data; 使用System.Management.Automation; 使用系统; 使用Google.Apis.Admin.Directory.directory_v1; 使用Google.Apis.Authentication.OAuth2; 使用Google.Apis.Authentication.OAuth2.DotNetOpenAuth;使用Google.Apis.Services ; 使用Google.Apis.Util;使用System.Security.Cryptography.X509Certificates ; 命名空间PSTest { [runInstaller的(真)] 公共类PsTest:PSSnapIn { ///<总结> ///指定PowerShell管理单元的说明。 ///< /总结> 公众覆盖字符串描述 {得到 {返回这是一个PowerShell管理单元,其中包括谷歌企业应用套件库; } } ///<总结> ///指定的描述本地化资源信息。 ///使用格式:resourceBaseName,说明。 ///< /总结> 公众覆盖字符串DescriptionResource {得到 {返回GoogleAppsPSSnapIn,这是一个PowerShell管理单元,其中包括谷歌企业应用套件库; } } ///<总结> ///指定PowerShell管理单元的名称。 ///< /总结> 公众覆盖字符串名称 {得到 {回归的GoogleApps } } ///<总结> ///指定的PowerShell管理单元供应商。 ///< /总结> 公众覆盖字符串卖方 {得到 {返回somecompany } } ///<总结> ///指定供应商的本地化资源的信息。 ///使用格式:resourceBaseName,VENDORNAME。 ///< /总结> 公众覆盖字符串VendorResource {得到 {返回GoogleAppsPSSnapIn,somecompany } } } [Cmdlet的(获取,GAppsUsers)] 公共类GetGAppsUsers:PSCmdlet { 保护覆盖无效ProcessRecord() { 常量字符串_serviceAccountCertPath = @C:\cert.p12 常量字符串_serviceAccountEmail = @[email protected] 常量字符串_serviceAccountUser = @[email protected] 无功证书=新X509Certificate2( _serviceAccountCertPath,notasecret,X509KeyStorageFlags.Exportable); 变种范围= DirectoryService.Scopes.AdminDirectoryUser.GetStringValue()+ @+ DirectoryService.Scopes.AdminDirectoryGroup.GetStringValue()+ @+ DirectoryService.Scopes .AdminDirectoryOrgunit.GetStringValue()+ @+ DirectoryService.Scopes.AdminDirectoryDeviceChromeos.GetStringValue()+ @+ DirectoryService.Scopes.AdminDirectoryDeviceMobile.GetStringValue()+ @+ DirectoryService.Scopes.AdminDirectoryDeviceMobileAction.GetStringValue(); VAR提供商=新AssertionFlowClient(GoogleAuthenticationServer.Description,证书) { ServiceAccountId = _serviceAccountEmail, SCOPE = @scopes }; 如果(_serviceAccountUser =的String.Empty!) { provider.ServiceAccountUser = _serviceAccountUser; } 变种AUTH =新OAuth2Authenticator< AssertionFlowClient>(供应商,AssertionFlowClient.GetState); 变种_directoryService =新DirectoryService中((新BaseClientService.Initializer(){验证器= AUTH})); VAR的服务= _directoryService.Users.List(); service.Customer =my_customer; service.OrderBy = UsersResource.ListRequest.OrderByEnum.FamilyName; service.SortOrder = UsersResource.ListRequest.SortOrderEnum.ASCENDING; service.MaxResults = 500; 变种ALLUSERS =新的List<使用者>(); 变种的用户= service.Execute(); 的Int64计数= 0; 如果(String.IsNullOrEmpty(users.NextPageToken)) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); 计数=(计数+ users.UsersValue.Count); Console.Write(数+...); } ,而(String.IsNullOrEmpty(users.NextPageToken)!) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); 计数=(计数+ users.UsersValue.Count); Console.Write(数+...); 用户= service.Execute(); 如果(String.IsNullOrEmpty(users.NextPageToken)) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); 计数=(计数+ users.UsersValue.Count); Console.Write(数+...); } } 的writeObject(ALLUSERS); } } } App.Config中 <?XML版本=1.0>?; <结构> <&运行GT; < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1> < dependentAssembly> < assemblyIdentity名称=System.Runtime公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Threading.Tasks公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Net.Http公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Net.Http.Primitives公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/> < / dependentAssembly> < / assemblyBinding> <启用=真/> loadfromRemoteSources; < /运行> <启动>< supportedRuntime版本=V4.0SKU =.net框架,版本= V4.0/>< /启动>< /结构> 融合登录 ***大会粘结剂日志条目(2013年8月31日@下午8时02分43秒)*** 操作失败。 连接结果:HR = 0x80070002。该系统找不到指定的文件。 C:: 大会经理从加载\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 下可执行的C运行:\Windows\ System32\WindowsPowerShell\v1.0\powershell.exe ---详细的错误日志如下。 ===预绑定状态信息=== 日志:用户= NinjaWinMontage\mosheldon 日志:显示名称= System.Net.Http.Primitives,版本= 1.5 .0.0,文化=中性公钥= b03f5f7f11d50a3a (完全指定)日志:应用平台=文件:/// C:/Windows/System32/WindowsPowerShell/v1.0/ 日志:初始PrivatePath = NULL 日志:动态基= NULL 日志:缓存基= NULL 日志:AppName的= powershell.exe 调用汇编:Google.Apis,版本= 1.5 .0.28972,文化=中立,公钥=空。 === 日志:此绑定LoadFrom加载上下文开始。 警告:本机映像不会LoadFrom上下文进行探测。本机映像将只默认加载上下文中进行探测,像的Assembly.Load()。 日志:使用应用程序配置文件:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config 日志:使用主机配置文件:日志:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config:从C使用计算机配置文件。 日志:后政策参考:System.Net.Http.Primitives,版本= 1.5.0.0,文化=中性公钥= b03f5f7f11d50a3a 日志:GAC查找不成功。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL。 日志:大会下载成功。文件试图设置:C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dll 日志:进入运行从 - 源安装阶段。 日志:大会名称为:System.Net.Http.Primitives,版本= 2.1.10.0,文化=中性公钥= b03f5f7f11d50a3a 警告:比较程序集名称时发生不匹配:主版本 ERR:程序集引用没有发现装配定义相匹配。 ERR:运行从源代码安装阶段失败,HR = 0x80131040。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL 。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE 。 日志:所有探测网址企图失败了。 ***大会粘结剂日志条目(2013年8月31日@下午8时02分43秒)*** 操作失败。 连接结果:HR = 0x80070002。该系统找不到指定的文件。 C:: 大会经理从加载\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 下可执行的C运行:\Windows\ System32\WindowsPowerShell\v1.0\powershell.exe ---详细的错误日志如下。 ===预绑定状态信息=== 日志:用户= NinjaWinMontage\mosheldon 日志:显示名称= System.Net.Http.Primitives,版本= 1.5 .0.0,文化=中性公钥= b03f5f7f11d50a3a (完全指定)日志:应用平台=文件:/// C:/Windows/System32/WindowsPowerShell/v1.0/ 日志:初始PrivatePath = NULL 日志:动态基= NULL 日志:缓存基= NULL 日志:AppName的= powershell.exe 调用汇编:Google.Apis,版本= 1.5 .0.28972,文化=中立,公钥=空。 === 日志:此绑定LoadFrom加载上下文开始。 警告:本机映像不会LoadFrom上下文进行探测。本机映像将只默认加载上下文中进行探测,像的Assembly.Load()。 日志:使用应用程序配置文件:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config 日志:使用主机配置文件:日志:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config:从C使用计算机配置文件。 日志:后政策参考:System.Net.Http.Primitives,版本= 1.5.0.0,文化=中性公钥= b03f5f7f11d50a3a 日志:GAC查找不成功。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL。 日志:大会下载成功。文件试图设置:C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dll 日志:进入运行从 - 源安装阶段。 日志:大会名称为:System.Net.Http.Primitives,版本= 2.1.10.0,文化=中性公钥= b03f5f7f11d50a3a 警告:比较程序集名称时发生不匹配:主版本 ERR:程序集引用没有发现装配定义相匹配。 ERR:运行从源代码安装阶段失败,HR = 0x80131040。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL 。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE 。 日志:所有探测网址企图失败了。 ***大会粘结剂日志条目(2013年8月31日@下午8时08分35秒)*** 操作失败。 连接结果:HR = 0x80070002。该系统找不到指定的文件。 C:: 大会经理从加载\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 下可执行的C运行:\Windows\ System32\WindowsPowerShell\v1.0\powershell.exe ---详细的错误日志如下。 ===预绑定状态信息=== 日志:用户= NinjaWinMontage\mosheldon 日志:显示名称= System.Net.Http.Primitives,版本= 1.5 .0.0,文化=中性公钥= b03f5f7f11d50a3a (完全指定)日志:应用平台=文件:/// C:/Windows/System32/WindowsPowerShell/v1.0/ 日志:初始PrivatePath = NULL 日志:动态基= NULL 日志:缓存基= NULL 日志:AppName的= powershell.exe 调用汇编:Google.Apis,版本= 1.5 .0.28972,文化=中立,公钥=空。 === 日志:此绑定LoadFrom加载上下文开始。 警告:本机映像不会LoadFrom上下文进行探测。本机映像将只默认加载上下文中进行探测,像的Assembly.Load()。 日志:使用应用程序配置文件:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config 日志:使用主机配置文件:日志:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config:从C使用计算机配置文件。 日志:后政策参考:System.Net.Http.Primitives,版本= 1.5.0.0,文化=中性公钥= b03f5f7f11d50a3a 日志:GAC查找不成功。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL。 日志:大会下载成功。文件试图设置:C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dll 日志:进入运行从 - 源安装阶段。 日志:大会名称为:System.Net.Http.Primitives,版本= 2.1.10.0,文化=中性公钥= b03f5f7f11d50a3a 警告:比较程序集名称时发生不匹配:主版本 ERR:程序集引用没有发现装配定义相匹配。 ERR:运行从源代码安装阶段失败,HR = 0x80131040。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL 。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE 。 日志:所有探测网址企图失败了。 ***大会粘结剂日志条目(2013年8月31日@下午8时08分35秒)*** 操作失败。 连接结果:HR = 0x80070002。该系统找不到指定的文件。 C:: 大会经理从加载\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll 下可执行的C运行:\Windows\ System32\WindowsPowerShell\v1.0\powershell.exe ---详细的错误日志如下。 ===预绑定状态信息=== 日志:用户= NinjaWinMontage\mosheldon 日志:显示名称= System.Net.Http.Primitives,版本= 1.5 .0.0,文化=中性公钥= b03f5f7f11d50a3a (完全指定)日志:应用平台=文件:/// C:/Windows/System32/WindowsPowerShell/v1.0/ 日志:初始PrivatePath = NULL 日志:动态基= NULL 日志:缓存基= NULL 日志:AppName的= powershell.exe 调用汇编:Google.Apis,版本= 1.5 .0.28972,文化=中立,公钥=空。 === 日志:此绑定LoadFrom加载上下文开始。 警告:本机映像不会LoadFrom上下文进行探测。本机映像将只默认加载上下文中进行探测,像的Assembly.Load()。 日志:使用应用程序配置文件:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.Config 日志:使用主机配置文件:日志:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config:从C使用计算机配置文件。 日志:后政策参考:System.Net.Http.Primitives,版本= 1.5.0.0,文化=中性公钥= b03f5f7f11d50a3a 日志:GAC查找不成功。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL。 日志:大会下载成功。文件试图设置:C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dll 日志:进入运行从 - 源安装阶段。 日志:大会名称为:System.Net.Http.Primitives,版本= 2.1.10.0,文化=中性公钥= b03f5f7f11d50a3a 警告:比较程序集名称时发生不匹配:主版本 ERR:程序集引用没有发现装配定义相匹配。 ERR:运行从源代码安装阶段失败,HR = 0x80131040。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL 。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE。 日志:尝试新的URL文件下载:/// C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE 。 日志:所有探测网址企图失败了。 新增System.Net.Http.Primitives版本2.1.10和1.5海关总署 GET-GAppsUsers:找不到方法:太虚System.Net.Http.HttpClientHandler.set_ AutomaticDecompression(System.Net.DecompressionMethods) 。 解决方案 SOLUTION 注册下面的GAC(GACUTIL /我的 DLL的路径的) System.Net.Http 2.1.10.0 System.Net.Http.Primitives 2.1.10.0 log4net的1.2.10.0 添加绑定重定向到C:\Windows\Microsoft .NET\Framework64\v4.0.30319\config\machine.config(替换当前运行时标签) <&运行GT; < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1> < dependentAssembly> < assemblyIdentity名称=System.Runtime公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Threading.Tasks公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.5.19.0NEWVERSION =2.5.19.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Net.Http公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/> < / dependentAssembly> < dependentAssembly> < assemblyIdentity名称=System.Net.Http.Primitives公钥=b03f5f7f11d50a3a文化=中性/> < bindingRedirect oldVersion =0.0.0.0-2.1.10.0NEWVERSION =2.1.10.0/> < / dependentAssembly> < / assemblyBinding> < /运行> Only have issues when trying to create a Powershell Cmdlet. I can execute the same code in the process record within a console app just fine. Thoughts were the App.config isn't redirecting the assembly but didn't have much success making it work. I used the nuget packages for the references to the Google-api-dotnet-clientSample Code herehttp://tinyurl.com/mbx3yleErrorhttp://i.imgur.com/xiEjwAR.pngGet-GAppsUsers : Could not load file or assembly 'System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.PsTest.csusing System.ComponentModel;using System.Collections.Generic;using Google.Apis.Admin.Directory.directory_v1.Data;using System.Management.Automation;using System;using Google.Apis.Admin.Directory.directory_v1;using Google.Apis.Authentication.OAuth2;using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;using Google.Apis.Services;using Google.Apis.Util;using System.Security.Cryptography.X509Certificates;namespace PSTest{ [RunInstaller(true)] public class PsTest : PSSnapIn { /// <summary> /// Specify a description of the PowerShell snap-in. /// </summary> public override string Description { get { return "This is a PowerShell snap-in that includes the Google Apps Lib"; } } /// <summary> /// Specify the localization resource information for the description. /// Use the format: resourceBaseName,Description. /// </summary> public override string DescriptionResource { get { return "GoogleAppsPSSnapIn,This is a PowerShell snap-in that includes the Google Apps Lib"; } } /// <summary> /// Specify the name of the PowerShell snap-in. /// </summary> public override string Name { get { return "GoogleApps"; } } /// <summary> /// Specify the vendor for the PowerShell snap-in. /// </summary> public override string Vendor { get { return "somecompany"; } } /// <summary> /// Specify the localization resource information for the vendor. /// Use the format: resourceBaseName,VendorName. /// </summary> public override string VendorResource { get { return "GoogleAppsPSSnapIn,somecompany"; } } } [Cmdlet("Get", "GAppsUsers")] public class GetGAppsUsers : PSCmdlet { protected override void ProcessRecord() { const string _serviceAccountCertPath = @"C:\cert.p12"; const string _serviceAccountEmail = @"[email protected]"; const string _serviceAccountUser = @"[email protected]"; var certificate = new X509Certificate2( _serviceAccountCertPath, "notasecret", X509KeyStorageFlags.Exportable); var scopes = DirectoryService.Scopes.AdminDirectoryUser.GetStringValue() + @" " + DirectoryService.Scopes.AdminDirectoryGroup.GetStringValue() + @" " + DirectoryService.Scopes.AdminDirectoryOrgunit.GetStringValue() + @" " + DirectoryService.Scopes.AdminDirectoryDeviceChromeos.GetStringValue() + @" " + DirectoryService.Scopes.AdminDirectoryDeviceMobile.GetStringValue() + @" " + DirectoryService.Scopes.AdminDirectoryDeviceMobileAction.GetStringValue(); var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate) { ServiceAccountId = _serviceAccountEmail, Scope = @scopes }; if (_serviceAccountUser != string.Empty) { provider.ServiceAccountUser = _serviceAccountUser; } var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState); var _directoryService = new DirectoryService((new BaseClientService.Initializer() { Authenticator = auth })); var service = _directoryService.Users.List(); service.Customer = "my_customer"; service.OrderBy = UsersResource.ListRequest.OrderByEnum.FamilyName; service.SortOrder = UsersResource.ListRequest.SortOrderEnum.ASCENDING; service.MaxResults = 500; var allUsers = new List<User>(); var users = service.Execute(); Int64 count = 0; if (String.IsNullOrEmpty(users.NextPageToken)) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); count = (count + users.UsersValue.Count); Console.Write(count + "..."); } while (!String.IsNullOrEmpty(users.NextPageToken)) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); count = (count + users.UsersValue.Count); Console.Write(count + "..."); users = service.Execute(); if (String.IsNullOrEmpty(users.NextPageToken)) { service.PageToken = users.NextPageToken; allUsers.AddRange(users.UsersValue); count = (count + users.UsersValue.Count); Console.Write(count + "..."); } } WriteObject(allUsers); } }}App.Config<?xml version="1.0"?><configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/> </dependentAssembly> </assemblyBinding> <loadfromRemoteSources enabled="true"/> </runtime><startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>Fusion Log *** Assembly Binder Log Entry (8/31/2013 @ 8:02:43 PM) ***The operation failed.Bind result: hr = 0x80070002. The system cannot find the file specified.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllRunning under executable C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe--- A detailed error log follows.=== Pre-bind state information ===LOG: User = NinjaWinMontage\mosheldonLOG: DisplayName = System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)LOG: Appbase = file:///C:/Windows/System32/WindowsPowerShell/v1.0/LOG: Initial PrivatePath = NULLLOG: Dynamic Base = NULLLOG: Cache Base = NULLLOG: AppName = powershell.exeCalling assembly : Google.Apis, Version=1.5.0.28972, Culture=neutral, PublicKeyToken=null.===LOG: This bind starts in LoadFrom load context.WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().LOG: Using application configuration file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.ConfigLOG: Using host configuration file:LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.LOG: Post-policy reference: System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aLOG: GAC Lookup was unsuccessful.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL.LOG: Assembly download was successful. Attempting setup of file: C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dllLOG: Entering run-from-source setup phase.LOG: Assembly Name is: System.Net.Http.Primitives, Version=2.1.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aWRN: Comparing the assembly name resulted in the mismatch: Major VersionERR: The assembly reference did not match the assembly definition found.ERR: Run-from-source setup phase failed with hr = 0x80131040.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: All probing URLs attempted and failed.*** Assembly Binder Log Entry (8/31/2013 @ 8:02:43 PM) ***The operation failed.Bind result: hr = 0x80070002. The system cannot find the file specified.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllRunning under executable C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe--- A detailed error log follows.=== Pre-bind state information ===LOG: User = NinjaWinMontage\mosheldonLOG: DisplayName = System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)LOG: Appbase = file:///C:/Windows/System32/WindowsPowerShell/v1.0/LOG: Initial PrivatePath = NULLLOG: Dynamic Base = NULLLOG: Cache Base = NULLLOG: AppName = powershell.exeCalling assembly : Google.Apis, Version=1.5.0.28972, Culture=neutral, PublicKeyToken=null.===LOG: This bind starts in LoadFrom load context.WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().LOG: Using application configuration file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.ConfigLOG: Using host configuration file:LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.LOG: Post-policy reference: System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aLOG: GAC Lookup was unsuccessful.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL.LOG: Assembly download was successful. Attempting setup of file: C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dllLOG: Entering run-from-source setup phase.LOG: Assembly Name is: System.Net.Http.Primitives, Version=2.1.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aWRN: Comparing the assembly name resulted in the mismatch: Major VersionERR: The assembly reference did not match the assembly definition found.ERR: Run-from-source setup phase failed with hr = 0x80131040.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: All probing URLs attempted and failed.*** Assembly Binder Log Entry (8/31/2013 @ 8:08:35 PM) ***The operation failed.Bind result: hr = 0x80070002. The system cannot find the file specified.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllRunning under executable C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe--- A detailed error log follows.=== Pre-bind state information ===LOG: User = NinjaWinMontage\mosheldonLOG: DisplayName = System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)LOG: Appbase = file:///C:/Windows/System32/WindowsPowerShell/v1.0/LOG: Initial PrivatePath = NULLLOG: Dynamic Base = NULLLOG: Cache Base = NULLLOG: AppName = powershell.exeCalling assembly : Google.Apis, Version=1.5.0.28972, Culture=neutral, PublicKeyToken=null.===LOG: This bind starts in LoadFrom load context.WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().LOG: Using application configuration file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.ConfigLOG: Using host configuration file:LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.LOG: Post-policy reference: System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aLOG: GAC Lookup was unsuccessful.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL.LOG: Assembly download was successful. Attempting setup of file: C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dllLOG: Entering run-from-source setup phase.LOG: Assembly Name is: System.Net.Http.Primitives, Version=2.1.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aWRN: Comparing the assembly name resulted in the mismatch: Major VersionERR: The assembly reference did not match the assembly definition found.ERR: Run-from-source setup phase failed with hr = 0x80131040.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: All probing URLs attempted and failed.*** Assembly Binder Log Entry (8/31/2013 @ 8:08:35 PM) ***The operation failed.Bind result: hr = 0x80070002. The system cannot find the file specified.Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dllRunning under executable C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe--- A detailed error log follows.=== Pre-bind state information ===LOG: User = NinjaWinMontage\mosheldonLOG: DisplayName = System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a (Fully-specified)LOG: Appbase = file:///C:/Windows/System32/WindowsPowerShell/v1.0/LOG: Initial PrivatePath = NULLLOG: Dynamic Base = NULLLOG: Cache Base = NULLLOG: AppName = powershell.exeCalling assembly : Google.Apis, Version=1.5.0.28972, Culture=neutral, PublicKeyToken=null.===LOG: This bind starts in LoadFrom load context.WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().LOG: Using application configuration file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.ConfigLOG: Using host configuration file:LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.LOG: Post-policy reference: System.Net.Http.Primitives, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aLOG: GAC Lookup was unsuccessful.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Windows/System32/WindowsPowerShell/v1.0/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.DLL.LOG: Assembly download was successful. Attempting setup of file: C:\Users\mosheldon\Desktop\PSTest\PSTest\bin\Debug\System.Net.Http.Primitives.dllLOG: Entering run-from-source setup phase.LOG: Assembly Name is: System.Net.Http.Primitives, Version=2.1.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3aWRN: Comparing the assembly name resulted in the mismatch: Major VersionERR: The assembly reference did not match the assembly definition found.ERR: Run-from-source setup phase failed with hr = 0x80131040.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.DLL.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives.EXE.LOG: Attempting download of new URL file:///C:/Users/mosheldon/Desktop/PSTest/PSTest/bin/Debug/System.Net.Http.Primitives/System.Net.Http.Primitives.EXE.LOG: All probing URLs attempted and failed.Added System.Net.Http.Primitives version 2.1.10 and 1.5 to GACGet-GAppsUsers : Method not found: 'Void System.Net.Http.HttpClientHandler.set_AutomaticDecompression(System.Net.DecompressionMethods)'. 解决方案 SOLUTIONRegister the following in GAC (gacutil /i path of dll)System.Net.Http 2.1.10.0System.Net.Http.Primitives 2.1.10.0log4net 1.2.10.0Add Binding Redirect to "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config" (Replace current runtime tag) <runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0" /> </dependentAssembly></assemblyBinding> </runtime> 这篇关于PowerShell命令缺少大会谷歌阿比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-20 15:20