I am trying to debug my PowerShell but I cannot get anything to output -
i have script here:
write-host "checking files" #to make more dynamical can save on 1 file #all file names including extension in different lines. #for example on path c:\filestowatch\watcher.txt #$filestowatch=get-content c:\filestowatch\watcher.txt #$filestowatch="felicio.txt","marcos.txt" $userfiles=dir c:\g\user\less\ $adminfiles=dir c:\g\admin\less\ #optionally instead of use if approach can #$adminfiles=dir c:\gt\admin\src\admin\wwwroot\content\less|? {$filestowatch -contains $_.name} #$userfiles=dir c:\gt\user-staging\src\user-staging\wwwroot\content\less|? {$filestowatch -contains $_.name} #loading in above manner first if statement on code bellow can removed because #we make sure $userfiles , $adminfiles have correct file monitor foreach($userfile in $userfiles) { if($filestowatch -contains $userfile.name) { $exactadminfile= $adminfiles | ? {$_.name -eq $userfile.name} |select -first 1 #my suggestion validate if got file. #by because of lazy not call test-path validate if got file #i'm assuming directory exact copy of each other find file. if($exactadminfile.lastwritetime -gt $userfile.lastwritetime) { write-verbose "copying $exactadminfile.fullname $userfile.fullname " copy-item -path $exactadminfile.fullname -destination $userfile.fullname -force } else { write-verbose "copying $userfile.fullname $exactadminfile.fullname " copy-item -path $userfile.fullname -destination $exactadminfile.fullname -force } } }
i understand there may problem script when runs not see output first line. can give me ideas on how can debug this?
here's how run (or try run script):
ps c:\gt> .\watcher.ps1
when tried script first line worked okay. there way can run script in debug mode give me idea wrong?
you should open script in ise can use debugger. select line want set breakpoint @ , hit f9 set it. go ahead , run script , once gets line, break debugger. there can start inspect variables , step through code locate issue.
some ise debugger shortcuts:
- f5 - run/continue
- f11 - step into
- f10 - step over
- f11 - step out
- ctrl+shift+d - display call stack
- ctrl+shift+l display breakpoints
- f9 - toggle breakpoint
- ctrl+shift+f9 - remove breakpoints
- shift+f5 - stop debugger
more info on debugging can found in files.
get-help about_debuggers
Comments
Post a Comment