我需要从函数设置一个全局变量,我不太清楚如何做到这一点.
# Set variables
$global:var1
$global:var2
$global:var3
function foo ($a, $b, $c)
{
# Add $a and $b and set the requested global variable to equal to it
$c = $a + $b
}
Run Code Online (Sandbox Code Playgroud)
调用函数:
foo 1 2 $global:var3
Run Code Online (Sandbox Code Playgroud)
最终结果:
$ global:var3设置为3
或者如果我这样调用函数:
foo 1 2 $global:var2
Run Code Online (Sandbox Code Playgroud)
最终结果:
$ global:var2设置为3
我希望这个例子有意义.传递给函数的第三个变量是要设置的变量的名称.
我到处搜索,尝试了许多不同的组合,但我似乎无法弄清楚如何从AD的组织部分获得“职位”。
这是我尝试过的一些事情
get-aduser -Filter * -SearchBase "Bob.Barker" -Properties sAMAccountName,Title
Get-ADUser -identity "Bob.Barker" -Filter * -Properties title | group title -NoElement
Run Code Online (Sandbox Code Playgroud)
另外,作为奖励问题,您将如何设置职位。
谢谢大家的帮助。
我一直试图弄清楚为什么我的代码无效.
我在CSV文件中有一个IP地址列表.从我想要获取计算机名称的IP地址列表中.当我执行时,无论我得到什么
使用"1"参数调用"GetHostByAddress"的异常:"指定了无效的IP地址." 在行:3 char:35 + [System.Net.dns] :: GetHostbyAddress <<<<("$ foo [0]")+ CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException
以下是CSV文件和使用的代码的示例:
CSV文件
值
192.168.0.11
192.168.0.12
192.168.0.13
192.168.0.14
正在使用的代码:
$foo = import-csv C:\test\test\test.csv
[System.Net.dns]::GetHostbyAddress("$foo[0]")
Run Code Online (Sandbox Code Playgroud) 首先,我唯一可用的是powershell.我已经想出如何比较两个数组; 但是,如果难以确定如何以我需要的格式恢复数据,我有点困难.
$foo = @(100, 200 ,300 ,400 ,500 ,600 ,700 ,800 ,900 ,1000)
$bar = @(50, 100, 600 , 900)
Run Code Online (Sandbox Code Playgroud)
期望的结果将是具有以下信息的阵列
50, 200, 300, 400, 500, 700, 800, 1000
Run Code Online (Sandbox Code Playgroud)
注意类似的值
100, 600 , 900
Run Code Online (Sandbox Code Playgroud)
被丢弃了
50
Run Code Online (Sandbox Code Playgroud)
将第二个数组中的数据添加到输出中.
这可能吗?
谢谢
我需要检索当月的天数,尽管我进行了研究,但我还没有找到PowerShell中的任何内容.以下是我目前为获得想要的结果而构建的内容.有更好的方法吗?
请注意,我仅限于Powershell
#check to see if this is a leap year
function LYC
{
if ([System.DateTime]::isleapyear((Get-Date).Year))
{
$Global:LY = True
}
}
#Get the number of days in current month
function fNOD
{
$MNum = (Get-Date).Month
switch ($MNum)
{
1 {$Global:DaysInMonth=31}
2 {
LYC
if (LY)
{
$Global:DaysInMonth=29
} else {
$Global:DaysInMonth=28
}
}
3 {$Global:DaysInMonth=31}
4 {$Global:DaysInMonth=30}
5 {$Global:DaysInMonth=31}
6 {$Global:DaysInMonth=30}
7 {$Global:DaysInMonth=31}
8 {$Global:DaysInMonth=31}
9 {$Global:DaysInMonth=30}
10 {$Global:DaysInMonth=31}
11 {$Global:DaysInMonth=30}
12 {$Global:DaysInMonth=31}
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在使用mySQL但是,这是我第一次必须执行如下查询.它有效,但我想知道是否有更好的方法来编写它.
SELECT * FROM foo WHERE bar = 10058 or bar = 90234 or bar = 98211 or bar 4002 or bar = 90023
Run Code Online (Sandbox Code Playgroud)
使用这种方法我可以提取的行数是否有限制?我弄错了吗?有没有更好的办法?
在这个特殊案例栏中的FYI将始终是唯一的