我的目标是从我的域中获取用户列表,其中包含以下信息:
- 显示名称-Country -Manager名称 - 最后登录日期
我正在运行以下脚本,除了LastLogon之外,一切看起来都很好.它将时间输入一堆随机数,如"129948127853609000".如何将其转换为DateTime格式?
Search-ADAccount -UsersOnly -SearchBase "OU=International,DC=mycompany,DC=com" -AccountDisabled:$false | Get-ADUser -Properties Name, manager, LastLogon | Select Name, manager, LastLogon | export-csv C:\Australia.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud) 运用
File.AppendAllText("c:\mytextfile.text", "This is the first line")
File.AppendAllText("c:\mytextfile.text", "This is the second line")
Run Code Online (Sandbox Code Playgroud)
如何将第二行文本显示在第一行下,就像我按下Enter键一样?这样做只需将第二行放在第一行旁边.
我可以使用此代码在Exchange服务器上发送电子邮件
Try
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential()
SmtpServer.Port = 25
SmtpServer.Host = "email.host.com"
mail = New MailMessage
mail.From = New MailAddress("myemail@email.com")
mail.To.Add("otheremail@email.com")
mail.Subject = "Equipment Request"
mail.Body = "This is for testing SMTP mail from me"
SmtpServer.Send(mail)
catch ex As Exception
MsgBox(ex.ToString)
End Try
Run Code Online (Sandbox Code Playgroud)
但是如何在身体上添加多条线?
我有一个简单的 powershell 脚本来启用 Exchange 中名为 test.ps1 的邮箱。这是脚本:
add-pssnapin microsoft.exchange.management.powershell.admin Enable-Mailbox -Identity 'gi joe' -database 'myserver\myserver 邮箱数据库 17'
如果我转到 Powershell 控制台并输入
./测试.ps1
它将成功运行。但是,如果我在 VB.net 中使用
Process.Start("powershell", "test.ps1")
终端闪烁得太快,我看不清它说什么,而且它也没有创建邮箱。为什么会发生这种情况,或者如何在读取错误之前阻止终端消失?
我正在使用以下代码来获取列表中计算机的状态和IP地址:
$csv = Get-Content TEST_MACHINES.csv
foreach ($computer in $csv)
{
try
{
Test-Connection $computer -Count 1 | Select-Object Address, IPV4Address
}
catch [System.Net.NetworkInformation.PingException]
{
'$computer is offline.'
}
}
Run Code Online (Sandbox Code Playgroud)
目的是获得每台机器的IP地址,如果机器离线,则打印“ $ computer offline”。
但是,它不会显示错误并显示消息,而是显示整个Test-Connection错误。如何获取仅在出现错误时显示我的消息的信息?
我正在尝试使用 Powershell 修改 %appdata%\LocalLow\Sun\Java\Deployment 中的文件。脚本很简单:
Add-Content "%appdata%\LocalLow\Sun\Java\Deployment\deployment.properties" "mydata"
Run Code Online (Sandbox Code Playgroud)
但是,它返回“无法找到部分路径 'C:\Users\MyUsername\Desktop\%appdata%\LocalLow\Sun\Java\Deployment\deployment.properties”
即使我指定了 %appdata%,它也会添加到脚本的当前目录中。如何指定 C:\Users\MyUsername\%AppData% 文件夹?
我正在尝试使用以下代码将文件的版本与指定版本进行比较,并告诉我哪个版本更高。
function Get-FileVersionInfo
{
param(
[Parameter(Mandatory=$true)]
[string]$FileName)
if(!(test-path $filename)) {
write-host "File not found"
return $null
}
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($FileName)
}
$file = Get-FileVersionInfo("C:\program files\internet explorer\iexplore.exe")
if($file.ProductVersion -gt "11.00.9600.17840") {
echo "file is higher version"
}
elseif($file.ProductVersion -eq "11.00.9600.17840") {
echo "file is equal version"
}
else {
echo "file is lower version"
}
echo "Product version is:" $file.ProductVersion
Run Code Online (Sandbox Code Playgroud)
仅供参考,使用 ProductVersion 而不是 FileVersion,因为 FileVersion 有时似乎包含额外的数据。
它返回“文件是较低版本”,即使它与“属性”中显示的版本相同。
我是否需要执行其他操作才能将 ProductVersion 属性与字符串进行比较?
我正在使用此代码将用户输入添加到文本文件:
<?php
//establish variables
$myFile = "chapter2.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$name = $_POST["name"];
$gnumber = $_POST["gnumber"];
fwrite($fh, $name);
fwrite($fh, "\n");
fwrite($fh, $gnumber);
fclose($fh);
?>
Run Code Online (Sandbox Code Playgroud)
但是,它将它添加到文本文件中,如下所示:
namegnumber
而不是这个:
名称
gnumber
为什么会这样?