Powershell在注册表数据输出中添加空间

问题描述 投票:1回答:1

我正在尝试创建一个小的脚本,该脚本可以很容易地向标准用户显示一些有效信息,以便从ServiceDesk获得IT协助。

Current output

因此,为了改善这一点,我试图确定是否可以在teamviewer结果中添加空格。

这是当前团队查看者ID结果的示例:1483547869

但是我想如果结果可以是:1483547869

这是一件小事,但对于标准用户而言,它更容易阅读。

这是我的代码:

Add-Type -AssemblyName System.Windows.Forms
$ip=get-WmiObject Win32_NetworkAdapterConfiguration|Where {$_.Ipaddress.length -gt 1} 
$ipaddress = $ip.ipaddress[0]
$hostname = [System.Net.Dns]::GetHostName()
$TeamViewerVersions = @('10','11','12','13','14','')

If([IntPtr]::Size -eq 4) {
    $RegPath='HKLM:\SOFTWARE\TeamViewer'    
} else {
    $RegPath='HKLM:\SOFTWARE\Wow6432Node\TeamViewer'
}

$ErrorActionPreference= 'silentlycontinue'

foreach ($TeamViewerVersion in $TeamViewerVersions) {
    If ((Get-Item -Path $RegPath$TeamViewerVersion).GetValue('ClientID') -ne $null) {
        $TeamViewerID=(Get-Item -Path $RegPath$TeamViewerVersion).GetValue('ClientID')
    }
}

$msgBoxInput = [System.Windows.Forms.MessageBox]::Show("Computer Name: $hostname`nIP Address: $ipaddress`nTeamViewer ID: $TeamviewerID`n`nWould you like to open Self Service Portal?", 'Quick Support','YesNo','Information')
    If ($msgBoxInput -eq 'Yes' ){
    start https://www.google.com/

    Else 
 }

Stop-Process -Id $PID
variables registry add spaces
1个回答
0
投票

这是格式化数字的非常简单的解决方案:

$TeamViewerDisplayID = $TeamViewerID.toString("### ### ### ###")

1483547869显示为1 483 547 869。注意:例如,如果您的电话号码包含9个字符,则上面的代码行将在开头添加一个空格。示例:"483547869"变为"_483 547 869"。因此,如果需要,可以在其中添加另一个if语句,以检查数字的长度并相应地设置其格式:

if ($TeamViewerID.length -gt 9) {
 $TeamViewerID.toString("### ### ### ###")
 } else {
 $TeamViewerID.toString("### ### ###")
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.