नमस्ते, मैं एक स्क्रिप्ट बनाने की कोशिश कर रहा हूं जो एक विशिष्ट फ़ोल्डर में सभी शब्द डॉक्स के फ़ॉन्ट को बदलता है, मैंने एक ऐसा बनाने में कामयाबी हासिल की है जो 1 दस्तावेज़ के लिए फ़ॉन्ट बदलता है, लेकिन यह काम नहीं कर सकता कि सभी फाइलों के लिए यह कैसे करें मेरी स्क्रिप्ट नीचे है

$Folder = Read-Host "Select Folder name"
$test = Test-Path C:\Users\andy.burton\Desktop\Layouts\$Folder\
$File = @
("0.bil","0.est","0.lbl","1.arm","1.bil","1.crd","1.env","1.est","1.frm","1.gp",
"1.hos","1.ins","1.lbl","1.lc","1.lmr","1.mls","1.NON","1.OP","1.pat","1.PRS
","1.rcl","1.rec","1.rmd","1.stm","10.pat","10.rec","11.pat","11.rec","12.pa
t","12.rec","13.pat","13.rec","14.PAT","14.rec","15.pat","16.pat","17.pat","18.pat","2.arm","2.bil","2.env","2.est","2.frm","2.gp","2.hos","2.ins","2.lbl","2.lc","2.lmr","2.mls","2.NON","2.pat","2.rcl","2.rec","2.rmd","2.stm","3.arm","3.bil","3.env","3.est","3.gp","3.hos","3.ins","3.lbl","3.lc","3.lmr","3.NON","3.pat","3.rec","3.rmd","3.STM","4.arm","4.bil","4.env","4.est","4.gp","4.hos","4.ins","4.lbl","4.lc","4.lmr","4.non","4.pat","4.rec","4.rmd","4.STM","5.arm","5.bil","5.env","5.est","5.gp","5.hos","5.ins","5.lbl","5.lc","5.lmr","5.non","5.pat","5.rec","5.rmd","6.bil","6.env","6.est","6.lbl","6.pat","6.rec","7.env","7.lbl","7.pat","7.rec","8.ENV","8.LBL","8.pat","8.rec","9.env","9.lbl","9.pat","9.rec","acchead.doc","address.lbl","apptreminder.email","apptreminder.sms","BMIBOOK.FRM","BUPA.OCR","clinicprint.rep","clinicprint2.rep","clinicprint2B.rep","clinicprint2C.rep","CLUB.BIL","Consent1.doc","consent2.doc","DEPOSIT.REC","ebs021.doc","ebs022.doc","EBS023.DOC","FConsent1.DOC","FEBS021.DOC","FEBS023.DOC","GP.OP","HCABOOK.FRM","InvCen.doc","InvFoot.doc","INVOICE.LBL","InvoiceGrid.doc","InvoiceGridNonVat.doc","InvoiceGridVAT.doc","InvoiceTotals.doc","InvoiceTotalsNonVAT.doc","InvoiceTotalsVAT.doc","J8160-95.LBL","J8160.LBL","J8162-95.LBL","J8162.LBL","J8163-95.LBL","J8163.LBL","J8165-95.LBL","J8165.LBL","J8360-95.LBL","J8360.LBL","J8362-95.LBL","J8362.LBL","J8363-95.LBL","J8363.LBL","J8365-95.LBL","J8365.LBL","J8560-95.LBL","J8560.LBL","J8562-95.LBL","J8562.LBL","J8563-95.LBL","J8563.LBL","J8565-95.LBL","J8565.LBL","L7160-95.LBL","L7160.LBL","L7161-95.LBL","L7161.LBL","L7162-95.LBL","L7162.LBL","L7163-95.LBL","L7163.LBL","L7164-95.LBL","L7164.LBL","L7165-95.LBL","L7165.LBL","L7166-95.LBL","L7166.LBL","L7167-95.LBL","L7167.LBL","L7168-95.LBL","L7168.LBL","L8162-95.LBL","letfoot.doc","lethead.doc","MC.BIL","NHS.PRS","NUFFBOOK.FRM","OPNOTE.OP","RecCen.doc","RECEIPT2.CC","ReceiptTotals.doc","recfoot.doc","remfoot.doc","shoulder1.jpg","shoulder2.jpg","TDL.FRM","TDL2.FRM","theatreprint.rep","VOUCHER2.CC")



if($test -eq $False) {

Copy-Item -Path 'C:\Users\andy.burton\desktop\Layouts\Arial 10' -Destination C:\Users\andy.burton\Desktop\Layouts\$Folder\ -Recurse


$file.ForEach({ 


$Word = New-Object -ComObject Word.Application

$Word.Visible = $False

$Doc = $word.Documents.Open()

$Selection = $word.Selection

$Doc.Select()

$Selection.Font.Name = "Calibri"

$Selection.Font.Size = 11

$Doc.Close()

$Word.Quit()

})


}


Else {Write-Warning "Folder Already Exists"}
1
Andy 2 अगस्त 2017, 16:32

2 जवाब

सबसे बढ़िया उत्तर

आप अपने $File सरणी के माध्यम से Foreach लूप और लूप का उपयोग करना चाहेंगे। आप $File का नाम बदलकर $Files भी कर सकते हैं

foreach($file in $Files)
{
     # peform font change here
}
0
Jason Snell 2 अगस्त 2017, 17:24

मुझे एक शेयर में शब्द दस्तावेज़ों के एक समूह के फ़ॉन्ट को बदलने की आवश्यकता थी और इंटरनेट पावरशेल का उपयोग करके पूरे शब्द दस्तावेज़ के फ़ॉन्ट को बदलने के परिणामों और संदर्भों के लिए इस पोस्ट पर वापस इंगित करता है। यह कोड और उत्तर इसे बहुत स्पष्ट रूप से नहीं दिखाता है इसलिए मैं इस कोड का योगदान देता हूं। यह कोड एक फ़ोल्डर में शब्द दस्तावेज़ प्राप्त करता है जो आपके द्वारा $Files अनुभाग में सूचीबद्ध कीवर्ड से मेल खाता है, फिर फ़ॉन्ट को $Selection.Font.Name = अनुभाग में जो कुछ भी आप डालते हैं उसे बदल देता है। मैंने इसे बनाने के लिए इस पोस्ट से मूल कोड को संशोधित किया है और मैंने इसे स्थानीय फ़ोल्डर के साथ-साथ सर्वर शेयर पर पहले ही परीक्षण कर लिया है। कृपया मुझे बताएं कि क्या इसे स्वीकृत किया जा सकता है। उदाहरण के लिए, प्रत्येक फ़ाइल को स्क्रीन करने के लिए आउटपुट करना अच्छा होगा जिसे बदला जा रहा है।

$Folder = "\\SERVER\SHARE\FOLDER\"
$Files = Get-ChildItem -Path $Folder -Recurse -Include *misc*.doc, *.misc*.docx, *Misc*.docx, *Misc*.doc, *MISC.docx, *MISC*.doc, *test*.doc, *test*.docx, whatever.doc

foreach($File in $Files)
{
    $Word = New-Object -ComObject Word.Application
    $Word.Visible = $false
    $Doc = $Word.Documents.Open($File.FullName)
    $Selection = $Word.Selection
    $Doc.Select()
    $Selection.Font.Name = "Verdana Pro SemiBold"
    $Doc.Close()
    $Word.Quit()
}

Write-Warning "Finshed With Font Change"
0
Rob Allison 5 फरवरी 2020, 20:36