$computers = get-content
"C:UsersAdministratorDesktopDAVIDTimeSyncFinalCheckTimeallips.txt"/span>
foreach ($strComputer in $computers) {
$TextOutput = net time $strComputer
$ip,$time,$time1 = ($TextOutput -split ' ')[3, 6, 7]
[PSCustomObject] @{
IP = $ip -replace ".*"/span>
時間 = $time $time1
}
我附上一張我的輸出圖片供參考。
我想做什么: 展開 IP,以便顯示整個 IP 地址。 最長的字串是172.32.5.111。 但它在以下地方一直斷線。172.32.5......,這也是輸出的情況。
我試過用PSCustomObject的-expand屬性,但說實話,今天是我第一次使用物件。 我在 C:UserAdministratorDesktopDAVIDTimeSyncFinalCheckTimeallips.txt 中也有一個 IP 串列
。每一行都列出了一個 IP 地址($srtComputer 是 IP 串列的變數,我試著把它作為 PSCustomObject 的存放位置,但這沒有幫助。
-replace 是為了洗掉添加到 net time 命令輸出中的內容(也許你不能擴展 net time 輸出?
uj5u.com熱心網友回復:
從我的評論繼續下去。你的基本代碼按設計作業:
如果你的檔案只有一個IPA,那么...Clear-Host
$computers = '127.0.0.1'。
foreach ($strComputer in $computers)
{
$TextOutput = net time `$strComputer
$ip, $time, $time1 = ($TextOutput -split ' ')[3,6, 7]
[PSCustomObject] @{
IP = $ip -replace ".*"/span>
時間 = $time $time1
}
}
# Results
<#
IP時間
-- ----
127.0.0.15:31:37PM
#>。
或者這樣,使用-replace和split(如果有其他東西在里面)......
Clear-Host
$computers = '127.0.0.1'/span>, '172.25.83.95'/span>.
foreach ($strComputer in $computers)
{
$TextOutput = (net time `$strComputer) -Replace '.*/span> -split ' is '
[PSCustomObject] @{
IP = $TextOutput[0]
時間 = $TextOutput[1]
}
}
或者使用RegEx(如果有其他東西在其中)...
Clear-Host
$computers = '127.0.0.1'/span>
foreach ($strComputer in $computers)
{
$TextOutput = net time$strComputer
[PSCustomObject] @{
IP = [regex]::Matches($TextOutput, 'd{1,3}.d{1,3}.d{1,3}'/span>).Value
Time = [regex]::Matches($TextOutput, '(d )/(d )/(d ). (d ):(d ). [A|P]M'/span>) .Value
}
}
我做了什么來解決這個問題:
我做了什么?
REPLACE GET-CONTENT WITH IMPORT-CSV
$strComputer with $ip
$computers to $computers.IP
And add an IP header to .csv file ip address list
*我想編輯我的原始如小如可能
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/316463.html
標籤:
