Script powershell

Welcome Forums Pester Script powershell

Viewing 1 reply thread
  • Author
    Posts
    • #99160
      Participant
      Topics: 1
      Replies: 1
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 1
      Replies: 1
      Points: 0
      Rank: Member

      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

      • #110020
        Senior Moderator
        Topics: 9
        Replies: 1265
        Points: 4,582
        Helping Hand
        Rank: Community Hero

        There are many issues in this script. What you would need is pure basics. I would suggest you to start from here and a highly recommended book “Learn PowerShell Toolmaking in a Month of Lunches” by Don Jones .

Viewing 1 reply thread
  • The topic ‘Script powershell’ is closed to new replies.