Tuesday, January 15, 2019

Managing windows time

Open an Administrator Command Prompt
tzutil /s "Central European Standard Time"
This config will set NT5DS configuration in ws32 config, meaning update time from domain hierarchy.
w32tm /config /syncfromflags:domhier /update /reliable:no
Check your peers afterwards
w32tm /query /peers

If you want to manually set time run it:
w32tm /config /manualpeerlist:ntp1.corpaddress.tdl /reliable:yes /syncfromflags:manual /update

w32tm /resync /rediscover
net stop w32time && net start w32time
Check it with W32tm /query /configuration

Syncing manually:

w32tm /stripchart /computer:ntp1.corpaddress.tdl
If you sync to Linux machine
/manualpeerlist:ntp1.corpaddress.tdl,0x1
Restore all settings:

net stop w32time
w32tm /unregister
w32tm /register
net start w32time

a

Monday, January 7, 2019

powershell commands

Creating new PS job:


Register-ScheduledJob -Name InstallXPS -ScriptBlock {Install-WindowsFeature -Name XPS-Viewer} -Trigger (New-JobTrigger -Once -At 05:20pm)

Register-ScheduledJob -Name ArchiveOLDfolders -ScriptBlock {compress-archive -Path F:\F00\MARKET\OLD\pol_proj\*,F:\F00\MARKET\OLD\pol_org\*,F:\F00\MARKET\OLD\Pol_Data\*,F:\F00\MARKET\OLD\Pol_Common\*,F:\F00\MARKET\OLD\Pol_Appl\* -DestinationPath F:\F00\MARKET\OLD\archive.zip} -Trigger (New-JobTrigger -Once -At 09:25am)

ipmo PSScheduledJob
$T = New-ScheduledTaskTrigger -Once -At 5:01PM
$action = New-ScheduledTaskAction -Execute 'C:\temp\compress.cmd'
$User= "NT AUTHORITY\SYSTEM"
Register-ScheduledTask -TaskName  ArchiveOldFiles -Action $action -User $User -RunLevel Highest –Force -Trigger $t


C:\tools\7-ZipPortable\App\7-Zip64\7z.exe a -r F:\F00\MARKET\OLD\pol_org.7z F:\F00\MARKET\OLD\Pol_org\* > C:\temp\pol_org.log
C:\tools\7-ZipPortable\App\7-Zip64\7z.exe a -r F:\F00\MARKET\OLD\pol_proj.7z F:\F00\MARKET\OLD\Pol_proj\* > C:\temp\pol_proj.log
C:\tools\7-ZipPortable\App\7-Zip64\7z.exe a -r F:\F00\MARKET\OLD\pol_data.7z F:\F00\MARKET\OLD\Pol_data\* > C:\temp\pol_data.log


Getting info when system was restarted

get-eventlog system | where-object {$_.eventid -eq 6006} | select -first 10

$out=Invoke-Command -ComputerName 'SFRFIDCSHP001t','SFRFIDCSHP004T','SFRFIDCSHP005T','SFRFIDCSHP006T' -ScriptBlock {get-eventlog system | where-object {$_.eventid -eq 6006} | select -first 5} 


$out | sort TimeGenerated -Descending | Export-Csv -Path c:\temp\sharepoint_restart2.csv