Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Why do I get permissions errors on only a small subset of my DCs?

$
0
0

Hello,

When I run the code below to all our Domain Controllers in the Forest, I get the following permission error only on 5 out of 100 DCs.  All DCS are in the Forest communicating properly and I'm a Domain Admin under which ID, or priveledges the script runs under.  Any ideas on why I get this error?  Thanks in advance.

Error

Access to the path '\\$ThisBox\C$\Temp\DC3' is denied.
    + CategoryInfo          : PermissionDenied: (C:\Program File...gs\20130503.log:FileInfo) [Copy-Item], UnauthorizedAccessExcep
   tion
    + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand<var id="yiv1334152633yui-ie-cursor"></var>

Code

Import-Module ActiveDirectory
#
# Grab all the DCs in the Domain
#
  $ThisBox    = $env:ComputerName
  $AllDCs     = Get-ADDomainController -filter * | Sort Name | Select -ExpandProperty Name
#
# Create Session IDs for all DCs
#
  $Sessid = New-Pssession $AllDCs
#
# Test if Directory exists and if so, remove it and create new one to park the data
#
  foreach ($DC in $AllDCs ) {
        If (Test-Path "file://$thisbox/C$/Temp/$DC" -pathtype container)  
           {
            Remove-Item "file://$thisbox/C$/Temp/$DC" -Recurse
            New-Item "file://$thisbox/C$/Temp/$DC" -type directory
           }
        Else
           {
            New-Item "file://$thisbox/C$/Temp/$DC" -type directory
           }
           } #endForeach
#
# Grab the Files on the DC and bring 'em to Mama
#
  Invoke-Command -session $Sessid -argumentlist $ThisBox -scriptblock {param($ThisBox) `
   Get-ChildItem –path 'c:\Program Files (x86)\MyData\Logs' -Recurse -Filter *.log  |
   Foreach-Object  { copy-item -Path $_.fullname -Destination "file://$thisbox/C$/Temp/$env:ComputerName"}}
#
# Remove the Session IDs
#
  Remove-Pssession $AllDCs<var id="yiv1421120946yui-ie-cursor"></var>


Thanks for your help! SdeDot


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>