header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Script not creating directories unless I step through
Last Post 11 May 2010 01:56 AM by George Howarth. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RichUser is Offline
New Member
New Member
Posts:3
Avatar

--
10 May 2010 08:25 AM
    I have written the below script to check and then create directories to put my backup files in using Beyond Compare.  My problem is that the directories are not made unless I step though the script using debugging step through.  This is my first script so it is not the most elegant one.  Can anyone critique and help me out?  Thanks in advance.




    testscript.txt

    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    11 May 2010 01:56 AM

    Try adding the -Force parameter:

    $myDocs = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\').Personal
    $Desktop = (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\').Desktop

    if (Test-Path -Path 'c:\testscripts\config\initdate.txt')
    {
     $sdate = Get-Content -Path 'c:\testscripts\config\initdate.txt'
     $initdate = Get-Date -Date $sdate
    }
    else
    {
     $initdate = Get-Date
     Set-Content -Path 'c:\testscripts\config\initdate.txt' -Value $initdate
    }

    $backday = Get-Date
    $diff = ($backday - $initdate).Days

    if ($diff -eq 0)
    {
     if (Test-Path -Path 'c:\testscripts\config\fullbackuppath.txt')
        {
      $fbPath = Get-Content -Path 'c:\testscripts\config\fullbackuppath.txt'
     }
     else
        {
      $fbPath = 'c:\testscripts\full1'
      Set-Content -Path 'c:\testscripts\config\fullbackuppath.txt' -Value $fbPath
     }
     if (Test-Path -Path $fbPath)
        {
      if (!(Test-Path -Path "$fbPath\Desktop"))
            {
       New-Item -Path "$fbPath\Desktop" -ItemType Directory -Force
      }
           
      if (!(Test-Path -Path "$fbPath\MyDocs"))
            {
       New-Item -Path "$fbPath\MyDocs" -ItemType Directory -Force
      }
     }
     else
        {
      New-Item -Path $fbPath -ItemType Directory -Force
     }
       
     Set-Content -Path 'c:\testscripts\config\desktop.txt' -Value 'log normal "c:\testscripts\config\synlog.txt"'
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "option confirm:yes-to-all"
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "criteria timestamp:2sec"
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "Load "
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "Load `"$Desktop`" `"$fbpath\Desktop`""
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "Sync Mirror:left->right"
     Invoke-Expression "c:\testscripts\config\desktop.bat"
     
     Set-Content -Path 'c:\testscripts\config\mydocs.txt' -Value 'log normal "c:\testscripts\config\synlog.txt"'
     Add-Content -Path 'c:\testscripts\config\mydocs.txt' -Value "option confirm:yes-to-all"
     Add-Content -Path 'c:\testscripts\config\mydocs.txt' -Value "criteria timestamp:2sec"
     Add-Content -Path 'c:\testscripts\config\mydocs.txt' -Value "Load "
     Add-Content -Path 'c:\testscripts\config\mydocs.txt' -Value "Load `"$myDocs`" `"$fbpath\mydocs`""
     Add-Content -Path 'c:\testscripts\config\desktop.txt' -Value "Sync Mirror:left->right"
     Invoke-Expression "c:\testscripts\config\mydocs.bat"
    }



    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer