Output Powershell Support

This topic contains 4 replies, has 2 voices, and was last updated by  postanote 3 months, 2 weeks ago.

  • Author
    Posts
  • #97719

    Battlesloth
    Participant

    Hello Support Forum,

    I am new to Powershell and have been working on the below, I am tryign to find example for my problem below to replace " : " with " – " for MAC Feild. So output should be example : " 00-50-24-58-B9-57 " instead of default return of " 00:50:24:58:B9:57 " then my output for configuration file would be complete. I will then look at XML output later.

    #Call OS Version Windows Then Run correct Config.txt output for corresponding OS
    $OS = (get-itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
    #Check for Windows 2016 Datacenter Server
    if ($OS -eq 'Windows Server 2016 Datacenter') {
    $SaveLocation = 'c:\windows\temp\config.txt'
    $HostName = (Get-WmiObject win32_computersystem).DNSHostName
    $Hostid = (Get-WmiObject win32_networkadapterconfiguration -filter "IPEnabled='True'" | Select-Object -Property macaddress).macaddress
    $IPid = (Get-NetIPAddress -AddressFamily IPv4 -AddressState Preferred -PrefixLength 24).IPv4Address
    
    $MEFConfig = @"
    
    
    
    
    
    
    
    
    
    
    
    "@
    
    Set-Content -Path $SaveLocation -Value $MEFConfig -Force
    }
    #Else Fails and produce Output Debug File
    Else {
    $SaveLocation = 'c:\windows\temp\ErrorConfig.txt'
    $OS = (Get-WmiObject -class win32_operatingsystem).version
    $HostName = (Get-WmiObject win32_computersystem).DNSHostName
    
    $MEFConfig = @"
     Version = $OS           >
    
    "@
    Set-Content -Path $SaveLocation -Value $MEFConfig -Force
    }
    
  • #97724

    Battlesloth
    Participant

    Can not update need 24-48 hours missing output data should show; 11-24

    @"

    "@

  • #97726

    Battlesloth
    Participant

    Well looks like text output is not support in forum you could try adding the following for test but its just MAC lien return i need assistance with to replace characters if this is possible.

    Can not update need 24-48 hours missing output data should show; 11-24

    @"
    Name="$HostName" Enabled="true" UseParentLogging="true"
    Credentials CredentialType="ParentSettings" Authenticated="true"/
    Host Enabled="true" LocalHost="true" Host="$HostName" IsHostValid="true" UseParentLogging="true"
    Credentials CredentialType="ParentSettings" Authenticated="true"/
    Client Enabled="true" IsClientValid="true" Name="$HostName" HostId="$Hostid" ID="" PluginType="WindowsEvent" ClientType="WinEvent"
    Configuration Key="Logs" Value="Application, Setup, Security, System"/
    Configuration Key="useWEF" Value="0"/
    /Client
    /Host
    /HostGroup
    /EventCollectorConfig
    "@

    Retrying above iwthout the " " chacetor to see if this assist.

  • #97729

    Battlesloth
    Participant

    Ok,

    So after a little digging around at some examples online I have come up with the following,

    (Get-WMIObject Win32_NetworkAdapterConfiguration -computername localhost|Select-Object MACAddress -Unique|ForEach {$_.MacAddress -replace ":","-"})
    

    However when I place this data into the output txt it create a white space in the trailing start and I carnt workout why.

    So my output give me " HostId=" 00-50-56-98-30-F4" " with the trailing Whitespace before HostID for MAC Details. Can anyone know how t oremove the whitespace ?

  • #97800

    postanote
    Participant

    Use the trim statement.

    Trim Your Strings with PowerShell

    One of the most fundamental rules for working with data is “garbage in, garbage out.” This means it is important to groom data before persisting it. It does not matter if the persisted storage is Active Directory, SQL Server, or a simple CSV file. One of the problems with “raw data” is that it may include stuff like leading spaces or trailing spaces that can affect sort and search routines. Luckily, by using Windows PowerShell and a few String methods, I can easily correct this situation.

    'blogs.technet.microsoft.com/heyscriptingguy/2014/07/18/trim-your-strings-with-powershell'

You must be logged in to reply to this topic.