Showing posts with label PowerShell. Show all posts
Showing posts with label PowerShell. Show all posts

Wednesday, 26 February 2014

Export and Import NTFS permission with Powershell from one domain to another

Steps:
Export Permissions
Modify the permissions.csv file - Change the domain name
Import permissions

Assumptions:
User name are same in both domains
Folder structure remains the same

Exports.ps1
Get-ChildItem "S:\Folder" -Recurse | ?{ $_.PsIsContainer } | %{
  $Path = $_.FullName
  # Exclude inherited rights from the report
  (Get-Acl $Path).Access | ?{ !$_.IsInherited } | Select-Object `
    @{n='Path';e={ $Path }}, IdentityReference, AccessControlType, `
    InheritanceFlags, PropagationFlags, FileSystemRights
} | Export-CSV "c:\temp\Permissions.csv"

Import.ps1
$par = Import-Csv -Path "c:\temp\Permissions.csv"

foreach ( $i in $par )
 {
 $path= $i.Path
 $IdentityReference= $i.IdentityReference
        $AccessControlType=$i.AccessControlType
        $InheritanceFlags= $i.InheritanceFlags
        $PropagationFlags=$i.PropagationFlags
        $FileSystemRights=$i.FileSystemRights
        echo $path $IdentityReference
        $acl = Get-Acl c:\temp
        $permission = $i.IdentityReference,$i.FileSystemRights,$i.AccessControlType
        $accessRule = new-object System.Security.AccessControl.FileSystemAccessRule $permission
        $acl.SetAccessRule($accessRule)
        #$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule     ($IdentityReference, $FileSystemRights, $InheritanceFlags, $PropagationFlags, $AccessControlType)
        #$objACL.AddAccessRule($objACE)
        $acl | Set-Acl $path
        }





Tuesday, 15 January 2013

PowerShell Posters

PowerShell Poster for Beginners


 
 http://ramblingcookiemonster.files.wordpress.com/2012/09/powershell-basic-cheat-sheet2.pdf

PowerShell Poster for Advanced Users


http://ramblingcookiemonster.files.wordpress.com/2012/09/powershell-cheat-sheet.pdf

PowerShell Poster for VMWare PowerCLI 5.1


http://blogs.vmware.com/vipowershell/files/2012/09/PowerCLI_5_1_Poster.pdf

PowerShell Poster for Exchange 2010
 
 http://blogs.technet.com/b/matabra/archive/2011/10/21/powershell-for-exchange-2010-cheat-sheet.aspx



Friday, 4 January 2013

Get Server Serial Number remotely - Powershell & VBScript

Powershell

Get-WMIObject -Class "Win32_BIOS" -Computer computername | select SerialNumber 


VBSCRIPT

strComputer = "computername"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
    Wscript.Echo "Manufacturer: " & objBIOS.Manufacturer
    Wscript.Echo "Serial Number: " & objBIOS.SerialNumber
Next

  

Thursday, 3 January 2013

Powershell XCopy equivalent

$dests=Get-Content -Path e:\dest.csv
$srcs=Get-Content -Path e:\src.csv
 foreach($src in $srcs)

{
   $x=0
   #Write-Host $srcs[$x] $dests[$x]
   Copy-Item $srcs[$x] $dests[$x] -Recurse -Force -Verbose
   $x=$x+1
}


dest.csv
\\server\d$\abc\
\\server\d$\xyz\

src.csv
\\fileserver\Users\abc\*
\\fileserver\Users\xyz\*

Friday, 14 December 2012

Get disk space with Powershell

$computername='MyComputerName'

Get-WmiObject win32_logicaldisk -ComputerName $computername -Filter {freespace>0} | Format-Table @{l='Computername';e={$computername}},@{l='Drive';e={$_.DeviceID}},@{l='Size';e={(($_.Size/1024)/1024)/1024}}, @{l='FreeSpace';e={(($_.FreeSpace/1024)/1024)/1024}}

Thursday, 22 November 2012

Determining Free Space in an Exchange 2010 Mailbox Database

[PS] C:\>Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto