我需要一些关于以下脚本输出的帮助,因此输出不会显示省略号(...).我试图插入"| Format-Table -Wrap -AutoSize"但我似乎没有把它弄好.
clear-host Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$services = new-object system.collections.sortedlist
$servers = (get-spfarm).servers
foreach ($server in $servers) {
foreach($service in $server.serviceinstances)
{
if ($service.status = "Online")
{
$s = $service.typename
if ($services.contains($s))
{
$serverlist = $services[$s]
$servername = $server.name
$services[$s] = "$serverlist - $servername"
}
else
{
$services[$s] = $server.name
}
}
} }
$services
Run Code Online (Sandbox Code Playgroud)
输出:
Name Value
---- -----
Access Database Service SE5APP - SE5FE - SE7FE - FAQ3
Application Discovery **and L...** SE5APP - SE5FE …Run Code Online (Sandbox Code Playgroud) 如何使用Powershell命令Get-ChildItem 计算特定文件夹(以及所有子文件夹)中的所有文件?随着(Get-ChildItem <Folder> -recurse).Count也文件夹进行计数,这不是我想要的.是否有其他可能快速计算非常大的文件夹中的文件?
有没有人知道关于Windows Powerhell的简短而好的教程?
我正在比较所有子文件夹与powershell的文件夹,并在我的本地机器上正常工作.但当我在服务器上尝试它时,它给我错误并追加
Microsoft.PowerShell.Core\FileSystem::\\
Run Code Online (Sandbox Code Playgroud)
到所有文件
如果有人早点做这样的工作,请帮忙
我的剧本是
$Path = '\\Server1\Folder1'
Get-ChildItem $Path -Recurse | ? { !$_.PSIsContainer } | % {
Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.Substring($Path)
$_
}
Run Code Online (Sandbox Code Playgroud)
它给我错误
Cannot convert argument "0", with value: "Microsoft.PowerShell.Core\FileSystem::\\Server1\Folder1\ServerListPowershell", for "Substring" to type "System.Int32": "Cannot convert value "M
icrosoft.PowerShell.Core\FileSystem::\\Server1\Folder1\ServerListPowershell" to type "System.Int32". Error: "Input string was not in a correct format.""
At C:\Users\cwr.satish.kumar\AppData\Local\Temp\898f72f1-a0d3-4003-b268-128c5efc9f2b.ps1:14 char:108
+ Add-Member -InputObject $_ -MemberType NoteProperty -Name RelativePath -Value $_.FullName.Substring <<<< ($Path)
+ CategoryInfo : NotSpecified: (:) …Run Code Online (Sandbox Code Playgroud) 在运行远程命令等时Enable-PsSession,Invoke-command我们需要提供这些命令的凭据.
我不希望每次执行这些命令时都提供凭据.
还可以说我在执行命令时将用户名存储在变量中并使用变量.我也想为密码这样做.我能这样做吗?
例如:
Invoke-Command -ComputerName mycomputer -ScriptBlock { Get-ChildItem C:\ } -credential mydomain\administrator
Run Code Online (Sandbox Code Playgroud)
所以这里我每次都在执行这些命令时提供密码.
命令应该如何从变量和其他机制自动获取用户名和密码?
我似乎无法NetSecurity在我的系统上找到该模块.我正在使用一个Amazon Windows 2008 Server R2 SP1实例.
Get-Module -ListAvailable 在我的环境中返回:
ActiveDirectory (I installed this)
ADRMS
AppLocker
BestPractices
BitsTransfer
CimCmdlets
ISE
Microsoft.PowerShell.Diagnostics/Host/Management/Security/Utility
Microsoft.WSMan.Management
PSDiagnostics
PSScheduledJob
PSWorkflow
PSworkflowUtility
ServerManaer
TroubleshootingPack
Run Code Online (Sandbox Code Playgroud)
我曾尝试安装WMF 3.0,但据报道已安装.
我想在从0到31的偶然数字的有序int [8]中找到所有连续数字.连续数字必须是最小长度3和最多5个数字.
在示例中,最后一个给我一个非常现实的问题.
例如:
int[] = new int[] { 3,7,14,16,23, 28, 29 ,30 } // no result (28,29 is length of 2 numbers)
int[] = new int[] { 4,5,6,7,18, 19, 20 ,21 } // 4,5,6,7 (yes! length of 4!!)
int[] = new int[] { 2.3.4.5.6.7.8.9 } // two results : 2,3,4 and 5,6,7,8,9
Run Code Online (Sandbox Code Playgroud)
我不想要解决方案,只是一个如何处理问题的例子,因为我正在尝试使用将军而且我真的被困住了!
非常感谢您的帮助!
基督教
- 这是我开始的代码(不是我厨房的汤)
public partial class Test2 : Form
{
public Test2()
{
InitializeComponent();
}
private void Test2_Load(object sender, EventArgs e)
{
int[] …Run Code Online (Sandbox Code Playgroud) 在c#中询问用户名和密码的更好方法是什么?
我需要他们传递一个DirectoryContextClass调用.
我需要在Powershell中使用类似Get-Credential的东西,将用户名和密码存储在变量中.
谷歌搜索它我发现这个工作有一些有趣的类,但框架4.0中没有内置类(例如:var cred = new credentialDialog()?
强安全性是可选的,只需掩盖输入密码字段即可.
谢谢你们
只是出于好奇,它不是'我必须拥有它',而是如何使用powershell中的system.tuple类声明一个元组?
我正在使用powershell.exe.config加载框架4.0,但我无法创建元组.
试试这个:
PS C:\ps1> $a = [System.Tuple``2]::Create( "pino", 34)
Chiamata al metodo non riuscita. [System.Tuple`2] non contiene un metodo denominato 'Create'.
In riga:1 car:31
+ $a = [System.Tuple``2]::Create <<<< ( "pino", 34)
+ CategoryInfo : InvalidOperation: (Create:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Run Code Online (Sandbox Code Playgroud)
抱歉意大利样品......
谢谢你的帮助.
编辑:
如果我尝试:
PS C:\ps1> $a = [System.Tuple]::Create(34,"pino")
Impossibile trovare un overload per "Create" e il numero di argomenti: "2".
In riga:1 car:28
+ $a = [System.Tuple]::Create <<<< (34,"pino")
+ CategoryInfo : NotSpecified: (:) [], …Run Code Online (Sandbox Code Playgroud) 在system.directoryservices.accountmanagement属性中LastLogon是LastLogOnTimeStampValue在所有域的域控制器上复制还是从所有可用域的 DC 的比较中派生的 LastLogon 属性的更新值?
我在 MSDN 中找不到这个属性被占用的地方。
我有一个看起来像这样的powershell.exe,它可以从我的命令行运行:
powershell.exe -noexit -command " & 'C:\Test\test.ps1' "
Run Code Online (Sandbox Code Playgroud)
但是,当我在当前用户的runonce-key中完全按照那种方式输入该条目时,没有任何反应.
从runonce调用powershell.exe传递参数或运行的正确方法是什么?