PowerShell能够提取1492条记录的列表。当我将ldap3模块与Python配合使用时,我的记录数已达到1000条。请帮助我将Python代码更改为超出限制。
PowerShell输入: get-aduser -filter * -SearchBase "OU=SMZ USERS,OU=SMZ,OU=EUR,DC=my_dc,DC=COM" | Measure-Object
输出:计数:1492平均:总和:最大值:最小值:属性:
import json
from ldap3 import Server, \
Connection, \
AUTO_BIND_NO_TLS, \
SUBTREE, \
ALL_ATTRIBUTES
def get_ldap_info(u):
with Connection(Server('my_server', port=636, use_ssl=True),
auto_bind=AUTO_BIND_NO_TLS,
read_only=True,
check_names=True,
user='my_login', password='my_password') as c:
c.search(search_base='OU=SMZ Users,OU=SMZ,OU=EUR,DC=my_dc,DC=com',
search_filter='(&(samAccountName=' + u + '))',
search_scope=SUBTREE,
attributes=ALL_ATTRIBUTES,
size_limit = 0,
paged_criticality = True,
paged_size = None,
#attributes = ['cn'],
get_operational_attributes=True)
content = c.response_to_json()
result = json.loads(content)
i = 0
for item in result["entries"]:
i += 1
print(i)
get_ldap_info('*')
Run Code Online (Sandbox Code Playgroud) 在PowerShell版本5.1.15063.726中运行以下命令
@"
$(foreach ($Number in 1..4) {"$Number`r`n"})
"@
Run Code Online (Sandbox Code Playgroud)
结果是
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
在每行的新行之后似乎添加了尾随空格.
我想也许这是一个怪癖
`r`n
Run Code Online (Sandbox Code Playgroud)
但使用[Environment]::NewLine具有相同的问题:
@"
$(foreach ($Number in 1..4) {"$Number" + [Environment]::NewLine})
"@
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
在没有迭代的情况下做一些看似平等的事情按预期工作:
@"
$("1`r`n" + "2`r`n" + "3`r`n" + "4`r`n")
"@
1
2
3
4
Run Code Online (Sandbox Code Playgroud)
以下也有效:
@"
$("1" + [Environment]::NewLine)$("2" + [Environment]::NewLine)$("3" + [Environment]::NewLine)$("4" + [Environment]::NewLine)
"@
@"
$("1`r`n")$("2`r`n")$("3`r`n")$("4`r`n")
"@
Run Code Online (Sandbox Code Playgroud)
以下不起作用,导致新行后的奇数额外空格:
@"
$(1..4 | ForEach-Object {"$_`r`n"})
"@
@"
$(1..4 | ForEach-Object {$("$_`r`n")})
"@
Run Code Online (Sandbox Code Playgroud)
想想也许这个问题与在循环中返回多个字符串有关,我试图构建一个字符串,然后返回那个有效的循环形式:
$String = …Run Code Online (Sandbox Code Playgroud) 我试图找出如何解析IP地址的数组.到目前为止,我已经解决了如何将IP解析为DNS主机名的问题:
Function Get-IP-Hostname
{
Param([string[]]$array)
$array.length
foreach ($element in $array)
{
$hname = [System.Net.Dns]::GetHostByAddress($element).HostName
$regex = "[regex] (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})"
@{$element = $hname}
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行
Get-IP-Hostname 192.168.150.xx 192.168.151.xx
Run Code Online (Sandbox Code Playgroud)
有一堆IP我必须使用逗号分割,分隔字符串 - 我的RegEx似乎没有逗号分裂.
我想获得这个输出:
> Name Value
>
> ---- -----
> 192.168.150.xx ank70dom07.akgroup.com
> 192.168.151.xx ank70dom07.akgroup.com
Run Code Online (Sandbox Code Playgroud)
我是PowerShell的新手,非常感谢任何帮助.
谢谢!
快速提问。我有以下几点:
$domain = "my.new.domain.com"
$domain.Split('.')[0,1]
Run Code Online (Sandbox Code Playgroud)
...返回值:
my
new
Run Code Online (Sandbox Code Playgroud)
那太好了,除了我需要最后两个(domain.com),并且不确定如何做到这一点。不幸的是,拆分的数量是可变的(例如test.my.new.domain.com)。一个人怎么说“到底并计数X向后分裂”?
有没有办法从Get-Help命令获取PowerShell cmdlet的返回类型?我更喜欢在没有实际调用命令的情况下获取此信息并使用GetType()它.好像对象返回类型应该在文档的某个地方?
示例:我输入Get-Help Get-Content.在文档中它告诉我它返回一个String对象?或String[]对象?
我需要提供一些标志Get-Help来获取这些信息吗?
I have a powershell script in host which copy some files and starts the container.
#Copy File
docker cp "D:\addApplication.ps1" website:/inetpub/wwwroot/
#Start Container
docker start website
Write-Host 'Process has started'
#Execute Container
docker exec -ti website powershell
#Run Script
Invoke-Expression "C:\inetpub\wwwroot\addApplication.ps1"
Run Code Online (Sandbox Code Playgroud)
Second last command executes fine but last command will only execute when I exit the container session and returns error(File Not Found which is because it finds that file on host)
Question: Is there anyway I can execute the …
我正在尝试使用Powershell DSC安装URL重写器并且它一直在失败.当我删除安装重写器的步骤时,脚本会成功.
我的设置是使用Visual Studio Team Services(VSTS)构建和发布管道我执行ARM模板来创建一个缩放集,指向powershell dsc脚本.
"extensionProfile": {
"extensions": [
{
"name": "Microsoft.Powershell.DSC",
"properties": {
"publisher": "Microsoft.Powershell",
"type": "DSC",
"typeHandlerVersion": "2.72",
"autoUpgradeMinorVersion": true,
"forceUpdateTag": "[parameters('dscVmssUpdateTagVersion')]",
"settings": {
"configuration": {
"url": "https://myblobname.blob.core.windows.net/dsc/scalesetSetup.zip",
"script": "prepareServer.ps1",
"function": "PrepareServer"
},
"configurationArguments": {
"nodeName": "localhost",
"envName": "[parameters('envName')]"
}
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
在这个脚本中,我正在启用Windows功能,安装Web部署和URL重写器.当没有安装重写器时一切正常,但是当我以下列任何一种方式添加它时失败.
DSC脚本实际上看起来像:
Configuration PrepareServer
{
Param ( [string] $nodeName, [string] $envName )
Import-DscResource -ModuleName PSDesiredStateConfiguration
Node $nodeName
{
# Web Server
WindowsFeature WebServerRole
{
Name = "Web-Server"
Ensure = "Present"
} …Run Code Online (Sandbox Code Playgroud) 我有一个PowerShell脚本,具有以下内容 hashtable
[HashTable]$folder_and_prefix = @{}
Run Code Online (Sandbox Code Playgroud)
在我的脚本中的某个点之后我不再需要它hashtable,我尝试了:
Remove-Variable $folder_and_prefix
但是我收到以下错误:
Remove-Variable:找不到名为'System.Collections.Hashtable'的变量
是否有可能删除我不再需要的hastable?
我想要替换字符串中的字符然后拆分它.示例如下:
$in = "string with spaces"
$out = $in -replace 's' | $_.Split(' ')
Run Code Online (Sandbox Code Playgroud)
导致ExpressionsMustBeFirstInPipeline.
为什么这不起作用?
我熟悉BASH语法如何处理此请求,但无法在PowerShell中找到实现此请求的方法。
BASH示例:
for x in `ls .`; do something with ${x}; done
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用PowerShell执行相同的操作(出于演示目的,语法不正确)...
ForEach ($group in `$wsus.GetComputerTargetGroups()`)
Run Code Online (Sandbox Code Playgroud)
...我显然收到语法错误。
从BASH到PowerShell的翻译是这里的问题。:D