小编Kik*_*opu的帖子

不包含拆分方法

这是我的代码:

$fPath = Get-Content .\param.txt | Select-String 'adresse' -SimpleMatch
fPath = $fPath.split("=")[1]
$fPath

$paramListe = Get-Content .\param.txt | Select-String 'type' -SimpleMatch
$paramListe = $paramListe.split("=")[1]
$paramListe

$seuil = Get-Content .\param.txt | Select-String 'seuil' -SimpleMatch
$seuil = $seuil.split("=")[1]
$seuil = $seuil

$relanceAuto = Get-Content .\param.txt | Select-String 'relanceAuto' -SimpleMatch
$relanceAuto = $relanceAuto.split("=")[1]
$relanceAuto
Run Code Online (Sandbox Code Playgroud)

这是导入的.txt:

adresse=o:\******\******\DataIntegrator
type=logiciel
seuil=0
relanceAuto=yes
Run Code Online (Sandbox Code Playgroud)

我希望这些变量得到"="符号旁边的值.但每次我启动程序时,它都会告诉我那些不是字符串:

[Microsoft.Powershell.Commands.MatchInfo]没有名为"split"的方法.

有人可以向我解释为什么它不起作用吗?

powershell split

1
推荐指数
1
解决办法
5822
查看次数

日期时间无效

$tmpCreated = dir | Sort CreationTime -Descending | Select CreationTime -First 1 
    $tmpCreated = [string]$tmpCreated
    $tmpCreated = $tmpCreated.split("=")[1]
    $tmpCreated = $tmpCreated.split("}")[0]
Run Code Online (Sandbox Code Playgroud)

这是我想要作为DateTime得到的变量.我想用这个命令比较两个日期:

$timeDiff = new-timespan –Start $tmpLast –End $tmpCreated
Run Code Online (Sandbox Code Playgroud)

$tmpLast工作良好.但是当我尝试启动时出现错误,说-End参数因$tmpCreated转换失败而无法使用.但这里是它包含的字符串:11/30/2015 11:57:01.那么,有人知道这有什么问题吗?

powershell datetime

1
推荐指数
1
解决办法
89
查看次数

PSObject - 带条件的属性

我想在这部分代码中添加条件:

$objInfos = New-Object PSObject -Property @{
                    Dossier = [string]"$($logs[0])"
                    "Taille totale" = [double]$logs[1]
                    "Categorie recherchee" = [double]$logs[2]
                    "Pourcentage" = [double]$logs[3]
                    "Date de dernier acces" = [DateTime]"$($logs[5])"
}
Run Code Online (Sandbox Code Playgroud)

我需要每个案例都有条件,比如:

$objInfos = New-Object PSObject -Property @{
                    if ($test -eq 1){
                        Dossier = [string]"$($logs[0])"
                    }
                    "Taille totale" = [double]$logs[1]
                    "Categorie recherchee" = [double]$logs[2]
                    "Pourcentage" = [double]$logs[3]
                    "Date de dernier acces" = [DateTime]"$($logs[5])"
}
Run Code Online (Sandbox Code Playgroud)

我试过这种方法,但没有用

散列文字中的键后缺少“=”运算符。

请问有人知道怎么做吗?

powershell powershell-2.0 psobject

0
推荐指数
1
解决办法
1847
查看次数

标签 统计

powershell ×3

datetime ×1

powershell-2.0 ×1

psobject ×1

split ×1