Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a script which outputs the results to a text file with 'Out-File -Append'
I want to add a few lines to the text file:
$time = (Get-Date -format dd-MM_HH-mm)
Write-Host "*********************************************************************"
Write-Host "New Reading - $time"
Write-Host "*********************************************************************"
the above sends it to the console and not to the file itself
how do I put that in the file?
Thank you
12 REPLIES 12
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to look at Add-content - Alias AC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tried this in the script - gave me gibberish
Add-Content c:\sm_status.txt "`n*********************************************************************"
Add-Content c:\sm_status.txt "`nNew Reading - $time"
Add-Content c:\sm_status.txt "`n*********************************************************************"
+++++++++++++++++++
⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪乮睥删慥楤杮ⴠㄠⴰ㠰ㅟⴴ㠱⩮⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You need to review the help file
Man ac
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
read it - no go
tried this also:
Add-Content -path c:\sm_status.txt -value "`n*********************************************************************"
Add-Content -path c:\sm_status.txt -value "`nNew Reading - $time"
Add-Content -path c:\sm_status.txt -value "`n*********************************************************************"
I'm getting this:
⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪പഊ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀猀愀最攀猀礀猀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀猀愀最攀猀礀猀搀戀 瀀攀渀搀椀渀最 㜀㨀 㔀㨀㔀㐀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀昀洀最猀椀渀昀甀猀攀爀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀昀洀最猀椀渀昀甀猀攀爀搀戀 瀀攀渀搀椀渀最 㜀㨀 㐀㨀㈀㔀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀ഀ 愀ഀ 最ഀ 吀ഀ 椀ഀ 洀ഀ 攀ഀ 吀ഀ 匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀഀ䘀䴀䜀㌀ ㈀ 一吀䰀㨀猀焀氀猀栀愀爀攀瀀漀椀渀琀甀猀攀爀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀猀栀愀爀攀瀀漀椀渀琀甀猀攀爀搀戀 椀搀氀攀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀ഀ 匀 ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀渀攀氀猀漀渀猀渀愀瀀椀渀昀漀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀渀攀氀猀漀渀猀渀愀瀀椀渀昀漀 椀搀氀攀 㘀㨀㈀㔀㨀㌀㠀ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀ഀ 匀 ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀渀攀氀猀漀渀猀渀愀瀀椀渀昀漀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀渀攀氀猀漀渀猀渀愀瀀椀渀昀漀 椀搀氀攀 㘀㨀㈀㔀㨀㌀㤀ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀椀洀猀礀猀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀椀洀猀礀猀搀戀 椀搀氀攀 ㈀㨀㌀㘀㨀 㠀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀椀洀甀猀攀爀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀椀洀甀猀攀爀搀戀 瀀攀渀搀椀渀最 ㌀㨀㜀㨀㔀㘀 ഀഀഀ敎⁷敒摡湩〱〭弸㐱㌭ഷഊ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀猀愀最攀猀礀猀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀猀愀最攀猀礀猀搀戀 瀀攀渀搀椀渀最 㜀㨀 㜀㨀㌀㘀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀愀最吀椀洀攀吀匀ഀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀ ⴀⴀⴀⴀⴀⴀⴀⴀⴀഀ挀漀渀开昀洀最㨀猀焀氀昀洀最猀椀渀昀甀猀攀爀搀戀 挀栀昀昀洀最昀氀爀 㨀猀洀开昀洀最开猀焀氀昀洀最猀椀渀昀甀猀攀爀搀戀 瀀攀渀搀椀渀最 㜀㨀 㘀㨀 㠀 ഀഀഀഀ匀漀甀爀挀攀 䐀攀猀琀椀渀愀琀椀漀渀 匀琀愀琀甀猀 䰀ഀ 愀ഀ 最ഀ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see no issue
ac -path c:\test.log -value "---------------------"
ac -path c:\test.log -value "new reading $time"
ac -path c:\test.log -value "---------------------"
ac -path c:\test.log -value "`n---------------------"
here's the file
---------------------
new reading 10-08_13-11
---------------------
---------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it doesn't work on my machine - no idea why..
thanks though
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try using the add-content cmdlet.
Sent from my Windows Phone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let me see the whole script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
$time = (Get-Date -format dd-MM_HH-mm)
Write-Host "*********************************************************************"
Write-Host "New Reading - $time"
Write-Host "*********************************************************************"
$FasUser = "root"
$pass = (get-content c:\pass.txt)
$SecureFasPasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$FasCred = New-Object -TypeName System.Management.Automation.PSCredential ($FasUser, $SecureFasPasswd)
Connect-NaController -Name filer01 -Credential $FasCred
Add-Content -path c:\sm_status.txt -value "`n*********************************************************************"
Add-Content -path c:\sm_status.txt -value "`nNew Reading - $time"
Add-Content -path c:\sm_status.txt -value "`n*********************************************************************"
Get-NaSnapmirror -Location vol_01 | select source, destination, status, lagtimets | ft -AutoSize | Out-String -width 300 | Out-File c:\sm_status.txt -Append
Connect-NaController -Name filer02 -Credential $FasCred
Get-NaSnapmirror -Location vol_01 | select source, destination, status, lagtimets | ft -AutoSize | Out-String -width 300 | Out-File c:\sm_status.txt -Append
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, you can do a few things differently
First, I see you are just checking al your snapmirrors.. What's your threshold? You should have a trigger point, who wants to look at all your snapmirrors.
Also, you can look into using the excel com object or piping it to an HTML page. If you search some of my scripts that will get you started
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see an issue. Replace 'n with 'r'n. 'n is a line feed, which by itself is ok for unix. I bet you are on a windows machine. You need a carriage return and line feed or you will muck up your text file, thus the chinese-looking characters.
Sent from my Windows Phone
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪⨪പഊ上睥删慥楤杮ⴠㄠⴰ㠰㉟ⴰ㤰
thank you
