Lapas

ceturtdiena, 2016. gada 17. novembris

Copy data to other location and retain permissions

@echo off

SET SRC="\\server\share"
SET DST="C:\WHERE YOU WANT FILES TO GO"
SET LOG="C:\Robocopy.log"

ROBOCOPY %SRC% %DST% /E /ZB /MIR /SEC /SECFIX /COPYALL /R:1 /W:1 /V /TEE /LOG:%LOG%
@if errorlevel 16 echo ***ERROR *** & goto END
@if errorlevel 8  echo **FAILED COPY ** & goto END
@if errorlevel 4  echo *MISMATCHES *      & goto END
@if errorlevel 2  echo EXTRA FILES       & goto END
@if errorlevel 1  echo --Copy Successful--  & goto END
@if errorlevel 0  echo --Copy Successful--  & goto END
goto END

:END

PAUSE


Here's what the switches mean:
  • SRC:: Source Directory (drive:\path or \\server\share\path).
  • DST:: Destination Dir  (drive:\path or \\server\share\path).
  • /E :: copy subdirectories, including Empty ones.
  • /ZB :: use restartable mode; if access denied use Backup mode.
  • /MIR :: Mirrors a directory tree.
  • /SEC :: Copies files with security
  • /SECFIX ::Fixes file security on all files, even skipped ones.
  • /COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).  Copies the Data, Attributes, Timestamps, Owner, Permissions and Auditing info
  • /R:n :: number of Retries on failed copies: default is 1 million but I set this to only retry once.
  • /W:n :: Wait time between retries: default is 30 seconds but I set this to 1 second.
  • /V :: produce Verbose output, showing skipped files.
  • /TEE :: output to console window, as well as the log file.
  • /LOG:file :: output status to LOG file (overwrite existing log).
Source: community.spiceworks.com

ceturtdiena, 2016. gada 10. novembris

Clear session on FortiGate

1) Clear filter:
diagnose sys session filter clear

2) Add new filter:
diagnose sys session filter src 192.168.1.110
diagnose sys session filter dport 80
diagnose sys session filter dst 192.168.0.1


3) Check applied filter:
diagnose sys session filter

4) Remove filtered session:
diagnose sys session clear

Source: forum.fortinet.com

trešdiena, 2016. gada 26. oktobris

Ping to file with timestamp

Create batch file:
@echo: off 
set host=192.168.1.1
set logfile=Ping.txt
ping -l 1000 -t %host%|cmd /q /v /c "(pause&pause)>nul & for /l %%a in () do (set /p "data=" && echo(!time! !data!)&ping -n 2 %host%>nul" >> %logfile%


To test from command line use %a instead of %%a

Output:
9:21:50.24 Pinging 192.168.1.1 with 1000 bytes of data:
 9:21:51.29 Reply from 192.168.1.1: bytes=1000 time=43ms TTL=61


Source: stackoverflow.com

otrdiena, 2016. gada 6. septembris

Change Office 365 resource calendar default permitions

If you want to set that everyone can see who booked the resource - you must change default permissions on resource calendar.
Connect Exchange Online with PowerShell.

See permissions on resource calendar:
Get-MailboxFolderPermission -Identity resource@mail.com:\Calendar

FolderName  User       AccessRights
----------  ----       ------------
Calendar    Default    {AvailabilityOnly}
Calendar    Anonymous  {None}


Set permissions on resource calendar:
Set-MailboxFolderPermission -Identity resource@mail.com:\Calendar -User Default -AccessRights Reviewer

FolderName User     AccessRights
---------- ----     ------------
Calendar   Default  {Reviewer}
Calendar   Anonymous {None}


Resource: exchangeserverpro.com

trešdiena, 2016. gada 20. jūlijs

Get list of Hyper-V VM disks

Run in PowerShell: Get-VMHardDiskDrive | Select-Object -Property VMName, VMId, ComputerName, ControllerType, ControllerNumber, ControllerLocation, Path | Sort-Object -Property VMName | Out-GridView -Title "Virtual Disks"

Enter VM name or * to get all.

pirmdiena, 2016. gada 20. jūnijs

PS Get used space on all volumes

gwmi win32_volume -Filter ‘drivetype = 3’ | select driveletter, label, @{LABEL=’GBcapacity’;EXPRESSION={$_.capacity/1GB} }, @{LABEL=’GBfreespace’;EXPRESSION={$_.freespace/1GB} }

pirmdiena, 2016. gada 6. jūnijs

Reset VSS Writer status

Get VSS writers:
vssadmin list writers

To reset VSS Writer status from Retryable or Non-retryable error you need to restart Hyper-V Virtual Machine Management service. Service restart does not affect VM only your ability to manage VM  through Hyper-V Manager console.

Source: social.technet.microsoft.com

otrdiena, 2016. gada 3. maijs

Reset windows security settings to default.

secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose

Rename folders: WinDir%\System32\GroupPolicyUsers and WinDir%\System32\GroupPolicy

Sourc: microsoft.com and sevenforums.com

trešdiena, 2016. gada 13. aprīlis

Use INDEX(MATCH()) instead of LOOKUP() in Excel

=INDEX ( Column I want a return value from , MATCH ( My Lookup Value , Column I want to Lookup against , Enter “0” ))

Source: www.randomwok.com

ceturtdiena, 2016. gada 7. aprīlis

Get server's all active users mapped disks and ports

Powershell script made by b.koehler:

function Get-MappedDrives($ComputerName){
  $output = @()
  if(Test-Connection -ComputerName $ComputerName -Count 1 -Quiet){
    $Hive = [long]$HIVE_HKU = 2147483651
    $sessions = Get-WmiObject -ComputerName $ComputerName -Class win32_process | ?{$_.name -eq "explorer.exe"}
    if($sessions){
      foreach($explorer in $sessions){
        $sid = ($explorer.GetOwnerSid()).sid
        $owner  = $explorer.GetOwner()
        $RegProv = get-WmiObject -List -Namespace "root\default" -ComputerName $ComputerName | Where-Object {$_.Name -eq "StdRegProv"}
        $DriveList = $RegProv.EnumKey($Hive, "$($sid)\Network")
        if($DriveList.sNames.count -gt 0){
          foreach($drive in $DriveList.sNames){
          $output += "$($drive)`t$(($RegProv.GetStringValue($Hive, "$($sid)\Network\$($drive)", "RemotePath")).sValue)`t$($owner.Domain)`t$($owner.user)`t$($ComputerName)"
          }
        }else{write-debug "No mapped drives on $($ComputerName)"}
      }
    }else{write-debug "explorer.exe not running on $($ComputerName)"}
  }else{write-debug "Can't connect to $($ComputerName)"}
  return $output
}

<#
#Enable if you want to see the write-debug messages
$DebugPreference = "Continue"

$list = "Server01", "Server02"
$report = $(foreach($ComputerName in $list){Get-MappedDrives $ComputerName}) | ConvertFrom-Csv -Delimiter `t -Header Drive, Path, Domain, User, Computer

$report | Out-GridView
#>


Source: technet.microsoft.com

pirmdiena, 2016. gada 4. aprīlis

Set default windows ip on server with multiple ip addresses

Run PowerShell.
Get interface name:
Get-NetAdapter

Set status "SkipAsSource":
Set-NetIPAddress –InterfaceAlias <Interface> –SkipAsSource $True

ceturtdiena, 2016. gada 11. februāris

Delete Offline Files Cache

 
  • Open Registry editor (Execute Regedit from Run window)
  • Go to this key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSe\Services\Csc\Parameters
  • If Parameters key does not exist under CSC you can add it.
  • Now in the Parameters node create a new registry value with the name FormatDatabase of type REG_DWORD (i.e DWord 32-bit value)
  • Set the data in this new registry value to 1.
  • Close registry editor
  • Reboot the machine
Source: technlg.net

otrdiena, 2016. gada 9. februāris

Find HP ProCurves on network

Connect with telnet to core switch and run commands:
sho cdp neighbors det
or
sho lldp info remote-device 

Windows 10 expand jump list

If you want to see more Pinned and Recent item in your taskbar you need to modify/create these registry values
HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced\
Dword values - Start_JumpListItems and JumpListItems_Maximum

otrdiena, 2016. gada 12. janvāris

Check applied group policies

Run GUI Resultans Set of Policy - rsop.msc
Command line user policies: gpresult /Scope User /v
Computer policies: gpresult /Scope Computer /v

Source: How-To-Geek

sestdiena, 2016. gada 2. janvāris

"General access denied error’ (0x80070005)" when starting Hyper-V VM

Every Hyper-V virtual machines has a unique Virtual Machine ID (SID). If the Virtual Machine SID is missing from the security permissions on the .vhd or .avhd file, the virtual machine does not start.

icacls "D:\Virtual Hard Disks\VM.vhdx" /grant "NT VIRTUAL MACHINE\12345678-975B-469D-9A70-A31DA482AF2F":(F)

piektdiena, 2016. gada 1. janvāris

Run Powershell on remote server

Allow remote powershell: Enable-PSRemoting -Force
Open session to remote server: Enter-PSSession -ComputerName <remote server> -Credential administrator

Source: HowToGeek.com

Fix replication between DC and RODC


Symptoms: Sysvol and Netlogon shares may be missing;
                   nltest /server:<DC-NAME> /dsgetdc:<DOMAIN> /gc /force shows that RODC is active DC

Check for errors: DCDIAG /TEST:DNS and DCDIAG /CheckSecurityError
 
If replication between DC and RODC is broken and repadmin /syncall does not help - you can manually set DC replica as authoritative.

Open Regedit HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NtFrs\Parameters\Backup/Restore\Process at Startup
Set BurFlags hex value to D4 - This registry value marks the FRS replica as authoritative.
Restart the File Replication Service

Source: KB316790