![](/img/trans.png)
[英]How to run exchange powershell command automatically from batch file
[英]How to print powershell command from a batch file?
我正在尝试打印到文件 power-shell 命令。 网络目录中的文件。 这是我的代码:
@echo off
break> \\90.0.0.209\Britannica\backup\Maor_Tests \\90.0.0.209\Britannica\backup
echo
wmic computersystem get PrimaryOwnerNAME, model >> \\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt
wmic bios get serialnumber >> \\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt
wmic cpu get name >> \\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt
systeminfo | findstr C:"OS Name" >> \\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt
REM When I try to execute this command, I get gibbersh text only on that command.
PowerShell Get-PhysicalDisk | Format-Table -AutoSize | \\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt
@pause
如何从此批处理文件打印到该命令的文件?
在最后一行试试这个:
PowerShell Get-PhysicalDisk | Out-String | Add-Content '\\90.0.0.209\Britannica\backup\Maor_Tests\Test.txt'
不过,脚本有点乱,就像其他人所说的那样,为什么不在 PowerShell 中完成所有操作? 像这样的东西会给你一个更整洁的输出(请注意,这是纯 Powershell,不能按原样放在 CMD 文件中,而应该放在 .ps1 中):
$OutPutFile = '\\localhost\temp\test.txt'
$ComputerInfo = Get-ComputerInfo | Select-Object BiosSeralNumber,CsModel,CsName,CsPrimaryOwnerName,CsProcessors,OsName
$PhysicalDisks = Get-PhysicalDisk | Select-Object DeviceId,FriendlyName,Size
$ComputerInfoObject = [PSCustomObject]@{
'Name' = $ComputerInfo.CsName
'OS' = $ComputerInfo.OsName
'Model' = $ComputerInfo.CsModel
'Owner' = $ComputerInfo.CsPrimaryOwnerName
'CPU' = $ComputerInfo.CsProcessors.Name
'S/N' = $ComputerInfo.BiosSeralNumber
}
foreach ($Disk in $PhysicalDisks) {
$ComputerInfoObject | Add-Member -NotePropertyName "Disk $($Disk.DeviceId)" -NotePropertyValue "$($Disk.FriendlyName), Size: $([int]($Disk.Size/1e9))GB"
}
$ComputerInfoObject | Out-String | Set-Content -LiteralPath $OutPutFile
生成的文本文件如下所示:
Name : LABWORKSTATION
OS : Microsoft Windows 10 Pro
Model : All Series
Owner : Microsoft
CPU : Intel(R) Core(TM) i5-4670K CPU @ 3.40GHz
S/N : System Serial Number
Disk 0 : NVMe Samsung SSD 960, Size: 500GB
Disk 1 : Samsung SSD 840 EVO 500GB, Size: 500GB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.