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
}
Can not update need 24-48 hours missing output data should show; 11-24
@"
"@
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.
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 ?