Script powershell

This topic contains 1 reply, has 1 voice, and was last updated by  wackernie 1 month, 1 week ago.

  • Author
    Posts
  • #99160

    wackernie
    Participant

    Bonjour, jai fait un script powershell et j'aimerais avoir une aide, car le script ne fonctionne pas normalement je vous joins se que je dois faire, et le script que j'ai écrit, mais il ne renomme par mon répertoire.

    The Powershell script should do the following:
    – Test if directory "\\ ecarbssf0007 \% username% \ Home \ Documents" exists. If YES, Exit.
    – Test if directory "\\ ecarbssf0007 \% username% \ Home \ My Documents" exists. If YES, Rename directory in "Documents"

    This powershell script will be placed upstream of the redirection process of user directories.

    and here is my script

    $Path = "C:\My Documents"
    $OldText = "My Documents"
    $NewText = "Documents"
    $logFile = 'c:\temp\test.txt'

    $a = Get-Date
    "Lancement du Script de renommage : " + $a >> $logfile
    Get-ChildItem $Path -Recurse | %{$_.FullName} |
    Sort-Object -Property Length -Descending |
    % {cd\
    Write-Host $_
    $Item = Get-Item $_
    $PathRoot = $Item.FullName | Split-Path
    $OldName = $Item.FullName | Split-Path -Leaf
    $NewName = $OldName -replace $OldText, $NewText
    $NewPath = $PathRoot | Join-Path -ChildPath $NewName

    if ($OldName.Contains($OldText)) {
    {
    $a = Get-Date
    $erreurInfo = "Impossible de modifier " + $item.Fullname + " "+ $a
    $erreurInfo >> $logFile
    }

    }

    }

    $a = Get-Date
    "FIN : " + $a >> $logfile

  • #99162

    wackernie
    Participant

    Hello, I made a powershell script and I would like help, because the script does not work normally I join you what I have to do, and the script that I wrote, but it does not rename by my directory.

    The Powershell script should do the following:
    – Test if directory "\\ ecarbssf0007 \% username% \ Home \ Documents" exists. If YES, Exit.
    – Test if directory "\\ ecarbssf0007 \% username% \ Home \ My Documents" exists. If YES, Rename directory in "Documents"

    This powershell script will be placed upstream of the redirection process of user directories.

    and here is my script

    $Path = "C:\My Documents"
    $OldText = "My Documents"
    $NewText = "Documents"
    $logFile = 'c:\temp\test.txt'

    $a = Get-Date
    "Lancement du Script de renommage : " + $a >> $logfile
    Get-ChildItem $Path -Recurse | %{$_.FullName} |
    Sort-Object -Property Length -Descending |
    % {cd\
    Write-Host $_
    $Item = Get-Item $_
    $PathRoot = $Item.FullName | Split-Path
    $OldName = $Item.FullName | Split-Path -Leaf
    $NewName = $OldName -replace $OldText, $NewText
    $NewPath = $PathRoot | Join-Path -ChildPath $NewName

    if ($OldName.Contains($OldText)) {
    {
    $a = Get-Date
    $erreurInfo = "Impossible de modifier " + $item.Fullname + " "+ $a
    $erreurInfo >> $logFile
    }

    }

    }

    $a = Get-Date
    "FIN : " + $a >> $logfile

You must be logged in to reply to this topic.