Avatar of NVIT
NVITFlag for United States of America

asked on 

Using Out-file -Appended switch, WMIC output in file has unwanted NUL codes in Notepad++

Using Out-file -Append switch to file $FNRunCMD, WMIC output has unwanted
NUL codes in Notepad++. See image.

I tried changing $CMDStrFreeSpc to not use /format:csv
I haven't tried the other 'Encodings'. My understanding is ASCII is universal for text editors.

There are other Out-file -Append lines to the same output file $FNRunCMD in this script. But this is the only line using WMIC.

$CMDStrFreeSpc = "wmic /node:d2j7jsr1 logicaldisk where drivetype=3 get name, freespace, systemname, filesystem, size, volumeserialnumber /format:csv >>`"$FNLog`""

Open in new window


Out-File -InputObject $CMDStrFreeSpc -Append $FNRunCMD -Encoding ascii

Open in new window




User generated image
Powershell

Avatar of undefined
Last Comment
Qlemo
Avatar of oBdA
oBdA

Not sure why you would want to merge csv output with some other kind of text, but just use native methods instead of wmic:
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName d2j7jsr1 |
	Select-Object -Property Name, FreeSpace, SystemName, FileSystem, Size, VolumeSerialnumber |
	ConvertTo-Csv -NoTypeInformation |
	Add-Content -Path $FNLog

Open in new window

If all you want is a csv with the disk information, you can use Export-Csv directly:
Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName d2j7jsr1 |
	Select-Object -Property Name, FreeSpace, SystemName, FileSystem, Size, VolumeSerialnumber |
	Export-Csv -NoTypeInformation -Path $FNLog

Open in new window

Avatar of NVIT
NVIT
Flag of United States of America image

ASKER

>  Not sure why you would want to merge csv output with some other kind of text, but just use native methods instead of wmic:

I think I'm stuck in old ways and my ignorance of powershell haha.

As it is setup currently, ps creates the cmd file with multiple robocopy lines. At the end, I add the wmic line to get the disk space. Example:

robocopy "z:\cad\pjs\_MISCELLANEOUS-DETAILS" "g:\dir\Backup\BupOfRecentPjs\cad\pjs\_MISCELLANEOUS-DETAILS"   /xf Thumbs.db *.dwl* /e /np /nfl /ndl /r:0 /w:0 /dcopy:t /log+:"c:\local\CopyPjs10DaysOld_Rslt_Acad.txt"
robocopy "z:\cad\pjs\_UTILITY_NOTES" "g:\dir\Backup\BupOfRecentPjs\cad\pjs\_UTILITY_NOTES"   /xf Thumbs.db *.dwl* /e /np /nfl /ndl /r:0 /w:0 /dcopy:t /log+:"c:\local\CopyPjs10DaysOld_Rslt_Acad.txt"
wmic /node:d2j7jsr1 logicaldisk where drivetype=3 get name, freespace, systemname, filesystem, size, volumeserialnumber >>"c:\local\CopyPjs10DaysOld_Rslt_Acad.txt"

Open in new window


How would I add your first example as a ps call from that cmd file to replace my current wmic call?
Avatar of oBdA
oBdA

I'm not quite following what you're trying to do here, sorry.
Why and how exactly are you creating a cmd file from PowerShell? Just run the robocopy commands from PowerShell.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo