小编jya*_*yao的帖子

如何使用CSI.exe脚本参数

当你运行csi.exe /?(安装了Visual Studio 2015更新2),您将获得以下语法

Microsoft (R) Visual C# Interactive Compiler version 1.2.0.51106
Copyright (C) Microsoft Corporation. All rights reserved.

Usage: csi [option] ... [script-file.csx] [script-argument] ...
Run Code Online (Sandbox Code Playgroud)

我只是想知道如何将这个[ script-argument ] 传递给我的csx脚本文件.比方说,我的csx脚本(c:\ temp\a.csx)只有2行,如下所示

using System;
Console.WriteLine("Hello {0} !", <argument_from_commandLine>);
Run Code Online (Sandbox Code Playgroud)

我期望的是在运行以下命令行之后

csi.exe c:\temp\a.csx David
Run Code Online (Sandbox Code Playgroud)

我会得到

Hello David !
Run Code Online (Sandbox Code Playgroud)

但我只是不知道我应该在我的脚本文件中做什么,所以我可以将csi.exe [ script_argument ] 传递给我的脚本文件(替换).

在此先感谢您的时间和帮助.

c# scripting csi

13
推荐指数
1
解决办法
1982
查看次数

Invoke-Sqlcmd两次运行脚本

我遇到了一个非常奇怪的问题,可以重复。

基本上,我使用invoke-sqlcmd通过-inputfile来调用脚本文件,但是如果脚本文件有一些执行错误(例如插入到表中列不应该为null的表中),则脚本文件将被执行两次。我也可以从探查器看到两个执行。

这是重现此问题的方法(我的环境:Win 8.1 + SQL2014 + PS 5.0)

  1. 在数据库中创建两个表

    Use TestDB
    
    create table dbo.s (id int identity primary key, b varchar(50));
    
    create table dbo.t (id int primary key, s_id int, b varchar(50));
    alter table dbo.t add constraint fk_t foreign key (s_id) references dbo.s(id)
    
    Run Code Online (Sandbox Code Playgroud)
  2. 现在,使用以下两行创建一个sql文件(我们将其命名为c:\ temp \ t.sql)

    insert into dbo.s ( b) select  'hello world'
    insert into dbo.t (s_id, b) -- purposely missing id to cause an error
    select 1, 'good morning'
    
    Run Code Online (Sandbox Code Playgroud)
  3. 运行以下PS cmdlet

    invoke-sqlcmd -Server "<my_local_server>" -database TestDB …
    Run Code Online (Sandbox Code Playgroud)

sql-server powershell

6
推荐指数
1
解决办法
1160
查看次数

如何从本地文件夹安装/更新Powershell模块-设置内部模块存储库

我需要在一个生产盒上安装PowerShell模块(即sqlserver),但是生产服务器没有任何Internet连接。

我使用的另一种方法是使用save-module将模块文件保存到共享文件夹中,然后将文件从共享文件夹直接复制到生产服务器的PS模块路径中

c:\program files\WindowsPowerShell\Modules
Run Code Online (Sandbox Code Playgroud)

它可以工作,但是我只是想知道我们是否可以使用现有的方法,即安装模块,例如

install-module -name sqlserver -repository "my shared folder"
Run Code Online (Sandbox Code Playgroud)

该要求也扩展到更新模块。

使用保存模块然后进行复制和粘贴似乎非常不可靠,因为我不知道安装模块是否实际上会进行某些DLL文件注册或安装。

任何PS专家都可以提出一些建议,例如在没有Internet连接的情况下使用安装模块吗?

在此先感谢您的时间。

PS:我知道在SO上有个职位,但这对我没有帮助。

powershell powershellget

6
推荐指数
1
解决办法
4813
查看次数

我们可以更改PowerShell会话的LanguageMode吗?

我目前的环境是使用PowerShell V5的Windows 7企业版(SP1)

PSVersion = 5.0.10586.117

不知何故,当我尝试运行以下语句时(之前它运行良好)

new-object System.Net.WebClient
Run Code Online (Sandbox Code Playgroud)

我开始收到以下错误

无法创建类型. 此语言模式仅支持核心类型

我检查了

$ExecutionContext.SessionState.LanguageMode
Run Code Online (Sandbox Code Playgroud)

结果是:ConstrainedLanguage

我现在对如何将此LanguageMode更改为此URL中提到的"FullLanguage"感到茫然

我GOOGLE了四周,没有看到任何有关我的环境,我看到最接近的链接是这里在MS TechNet论坛.但在我的情况下,我不认为它是启用AppLocker(或者我是否必须要求我的网络管理员检查组策略?)并且我在本地计算机上也没有看到任何SRP(软件限制策略).

有人可以告诉我如何解决这个问题或如何检查导致这个LanguageMode更改的各个方面?或者有没有办法可以编辑LangugageMode值?在此先感谢您的帮助.

powershell

5
推荐指数
1
解决办法
7228
查看次数

如何使用 PowerShell 或 C# 将网页保存到 HTML 文件中?

我有以下链接,当我通过 Chrome 打开链接,然后右键单击页面,然后选择“另存为”将页面保存到 HTML 文件 (c:\temp\cu2.html)

在此处输入图片说明

保存后,我可以用 HTML 编辑器(比如 VS2015)打开这个 cu2.html 文件,我可以看到文件内部,有如下所示的标签

在此处输入图片说明

但是,如果我使用 IE11(而不是 Chrome)打开链接,然后将同一页面另存为 HTML 文件,则根本找不到此标签。实际上,IE11 保存的 html 文件与我可以使用下面的 PowerShell 脚本提取的内容相同。

#Requires -version 4.0
$url = 'https://support.microsoft.com/en-us/help/4052574/cumulative-update-2-for-sql-server-2017';

$wr = Invoke-WebRequest $url;
$wr.RawContent.contains('<table') # returns false

$wr.RawContent | out-file -FilePath c:\temp\cu2_ps.html -Force; #same as the file saved from the webpage to html file in IE
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:

为什么 Chrome 中保存的网页(作为 html 文件)与 IE 中的不同?

如何使用 PowerShell(或 C#)将此类网页保存为 HTML 文件(与 Chrome 中保存的文件相同)?

在此先感谢您的帮助。

html powershell google-chrome web

4
推荐指数
1
解决办法
1万
查看次数

Powershell 加载什么版本的 dll 文件?

当我在 Windows 10 中启动 PowerShell ISE 时,我可以运行以下代码

$dt = new-object "system.data.DataTable";
Run Code Online (Sandbox Code Playgroud)

我知道这只是可行的,因为 System.Data.dll 已加载,否则,将会出现错误,因为DataTable类来自 System.Data.dll

在我的计算机上,我安装了多个版本的.Net Framework,例如 v4.6.x、v4.7.x

所以我的问题是,一旦我的 PowerShell 启动

  1. 我如何知道加载了哪些 DLL 文件?
  2. 他们的版本是什么?

在此先感谢您的时间 !

dll powershell

2
推荐指数
1
解决办法
2133
查看次数

标签 统计

powershell ×5

c# ×1

csi ×1

dll ×1

google-chrome ×1

html ×1

powershellget ×1

scripting ×1

sql-server ×1

web ×1