0
私は、スクリプトを修正しようとすることだし、それは私がここにスレッドを失ったようです。私は常にログファイルの成功の結果を得ていますが、正直言って素晴らしい結果ですが、たとえソースフォルダを削除しても、成功します:(PowerShellのスクリプト
私はコーダーではありませんが、私はいくつかの機能が働いていますが、それでも機能しない関数は次のとおりです: 1-ソースフォルダまたはファイルが存在しない場合、Fail値を持つレジストリエントリを作成するはずです。 C:\ logs \ CopyTNSNames_1.0.log
ここであなたは私のコードであり、それはうまく動作するので、それを使用して自由に感じてくださいファイルをネットワーク共有から取得し、タイムスタンプ付きのバックアップを作成します。もちろん、一度固定されます:
# Function
Function writetolog ($nTxt){
$date = Get-Date
$sapce = ' '
$log_path = 'C:\logs\'
$log_name = $log_path + 'CopyTNSNames_1.0.log'
if(!(Test-Path -Path $log_path)){New-Item -ItemType directory -Path $log_path}
Add-content $log_name -value $date$sapce$nTxt
}
Function code_retour ($rc){
$date = Get-Date
$rc_ok = 0,3010
$Script_returnCode = 0
$CodeDeRetour = "Return code : ",$rc
if($rc_ok -contains $rc){
writetolog $CodeDeRetour
return $rc
}Else{
writetolog $CodeDeRetour
writetolog 'The script has failed'
writetolog ''
writetolog "**************************"
writetoreg ('Fail',$rc)
exit $rc}
}
Function writetoreg($status){
$date = Get-Date
$status_rc = 'RC = ' + $status[1]
$regpath_MyCompany = 'hklm:software\MyCompany'
$regpath_Tier = 'hklm:software\MyCompany\Applications'
$regpath_App = 'hklm:software\MyCompany\Applications\CopyTNSNames_1.0'
$regpath_DT = 'hklm:software\MyCompany\Applications\CopyTNSNames_1.0\Result'
if(!(Test-Path $regpath_MyCompany)){New-Item -Path $regpath_MyCompany}
if(!(Test-Path $regpath_Tier)){New-Item -Path $regpath_Tier}
if(!(Test-Path $regpath_App)){New-Item -Path $regpath_App}
if(!(Test-Path $regpath_DT)){New-Item -Path $regpath_DT}
If($status[0] -eq 'Succes'){
$result = 'Succes'
Set-ItemProperty -Path $regpath_DT -Name $result -Value $date}
If($status[0] -eq 'Failure'){
$result = 'Failure Timestamp ' + $date
Set-ItemProperty -Path $regpath_DT -Name $result -Value $status_rc}
}
cls
Function CopyOra
{
$PathFolder = "\\partage\ORAFiles\Source"
$DestinationFolder = "c:\Apps\Oracle\11.2\network\admin\"
if (!(test-path $DestinationFolder))
{
New-Item $DestinationFolder -ItemType Directory
"$(Get-Date) : Created folder $DestinationFolder" | Out-File "C:\Logs\CopyTNSNames_1.0" -Append
}
$Dir = get-childitem $PathFolder | Sort-Object Time -descending
$LOGFilesFound = $Dir | where { $_.extension -eq ".ora" }
"$(Get-Date) : processing files: $LOGFilesFound" | Out-File "C:\Logs\CopyTNSNames_1.0" -Append
write-host "$(Get-Date) : processing files: $LOGFilesFound"
foreach ($LOGFile in $LOGFilesFound)
{
write-host $PathFolder\$LOGFile
Try
{
If (Test-Path $DestinationFolder$LOGFile)
{
"$(Get-Date) : fichier trouvé $DestinationFolder$LOGFile ... Copie de backup en cours." | Out-File "C:\Logs\CopyTNSNames_1.0" –Append
$now=Get-Date -format "dd-MM-yyyy HH-mm"
$newFileName = "$LOGFile-$now"
copy-item -path "$DestinationFolder$LOGFile" -destination "$DestinationFolder$newFileName" -Container -Force:$true -Recurse
"$(Get-Date) : $DestinationFolder$newFileName créé." | Out-File "C:\Logs\CopyTNSNames_1.0" –Append
} else
{
write-host "$DestinationFolder$LOGFile non trouvé sur le poste"
"$(Get-Date) : $DestinationFolder$newFileName non trouvé localement." | Out-File "C:\Logs\CopyTNSNames_1.0" –Append
}
copy-item -path "$PathFolder\$LOGFile" -destination "$DestinationFolder$LOGFile" -Container -Force:$true -Recurse
"$(Get-Date) : Copy done $PathFolder\$LOGFile" | Out-File "C:\Logs\CopyTNSNames_1.0" –Append
}
Catch
{
"$(Get-Date) : copie non possible..." | Out-File "C:\Logs\" –Append
$Script_returnCode = code_retour $returnCode.ExitCode
write-host $returnCode.ExitCode
}
}
}
#Run main function
CopyOra
writetolog ""
writetolog "End of script"
writetolog "**************************"
writetoreg ("Success",$Script_returnCode)
exit $Script_returnCode
この問題の解決にお役立てください。よろしくです。 よろしくお願いします。
こんにちはとご返信いただきありがとうございます。 – derspinne
レジストリに書き込むことができないようです。 2017年2月14日午後01時56分51秒処理ファイル: 2017年2月14日午後01時56分51秒C:\アプリ\オラクル\ 11.2 \ネットワーク\管理者\非trouvéのlocalement。 2017年2月14日午後01時56分51秒Copieeffectuéeデ\\ partage \ ORAFiles \ソース\ tnsnames.oraの 2017年2月14日午後01時56分51秒リターンコード:0 2017年2月14日13時56: 51インポッシブルD'écrireDANSラベースデregistre、fonctionのwritetoreg 2017年2月14日13時56分51秒Erreurdétectée...詳細:インポッシブルデLierのL'引数のauparamètreの«パス»、車ILア・ラvaleurヌル。 、 親切にしてください。 – derspinne
あなたは今あなたのproblèmeへの説明をしています。レジストリのこの部分に書き込むことはできません – Esperento57