也许不是每个人都能理解我在阅读标题时遇到的问题,但我会解释:
我正在使用Powershell ISE创建一个脚本来帮助我使用sharepoint 2007 ...这个脚本 应该 从一个永远不会改变的文件夹中下载5个文件(比如一个模板文件夹)在此之前,将在您的硬盘驱动器(C:/ temporary)上创建一个名为" temporary" 的文件,其中下载这5个文件。
然后会打开一个窗口,您必须在其中输入4个输入,稍后将用于重命名文件。 (模板名称:999999_uuu_customer_projectname - > after:123456_BAM_Frank_Windows(这只是一个例子))。然后上传和重命名文件,并希望我想用我的脚本,但......
这个无用的Powershell ISE记住我的旧设置,所以如果我输入111111作为第一部分,然后完成脚本并再次启动它会记住111111或窗口不会打开就像一切都是随机的。
对于这个冗长的解释感到抱歉,我希望你能帮我解决这个问题(我在这里删除代码)
$webclient = New-Object System.Net.WebClient
$webclient.UseDefaultCredentials = $true
$credentials =$webclient.Credentials
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName ("System.Windows.Forms")
$fileurl = "https://workspace.cee.xxxxxx.com/content/00000100/Research/TestOffer/documents/"+$year+"/999999_uuu_customer_projectname/130_Offer_Documents/Review_01/" #xxxxxx stands for a value I am not allowed to display, sorry
$review_comments_year = "1617" #sepcific for the review_comment_file
$year = "FY_16-17" #for the general FY file (only change the numbers!)
$DropDownArray = @("BAM", "PAS", "AVT", "SRA", "NEC", "ITP", "ELD", "RFT", "SEE")
$objForm = New-Object System.Windows.Forms.Form #init -> initializing window form
$objForm.Text = "Input Window v0.5" #name -> the name which will be display in the top border of the window
$objForm.Size = New-Object System.Drawing.Size(300,250) #size -> set the size of the window
$objForm.StartPosition = "CenterScreen" #location -> where the window will appear on the screen
$objForm.FormBorderStyle = 'Fixed3D' #sizing -> fixes the size of the window so you cannot make it bigger
#OKButton -> creates a button with the value 'OK'
$OKButton = New-Object System.Windows.Forms.Button #initialization -> initializes the button
$OKButton.Location = New-Object System.Drawing.Size(75,180) #Location -> where the button is located in the window
$OKButton.Size = New-Object System.Drawing.Size(75,23) #Size -> defines the size of the button
$OKButton.Text = "OK" #value -> sets the value of the button to 'OK'
$objForm.Controls.Add($OKButton) #adding -> adds the button to the window
$OKButton.Add_Click($OKButton_OnClick)
$OKButton_OnClick = {
if (
($ParIDInbox.Text.Length -lt 6) -or
($ResearchGroupInbox.Text.Length -lt 3) -or
($CustomerInbox.Text.Length -lt 1) -or
($ProjectnameInbox.Text.Length -lt 1)
) {
[System.Windows.Forms.MessageBox]::Show("Please fill out all of the form fields", "ERROR",
[System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
}
else {
$ParID=$ParIDInbox.Text
$Research_Groups=$ResearchGroupInbox.Text
$Customer=$CustomerInbox.Text
$Projectname=$ProjectnameInbox.Text
Write-Host -f Yellow "$ParID | $Research_Groups | $Customer | $Projectname"
$objForm.Dispose()
}
}
#CancelButton -> creates a button with the value 'Cancel'
$CancelButton = New-Object System.Windows.Forms.Button #initialization -> initializes the button
$CancelButton.Location = New-Object System.Drawing.Size(150,180) #Location -> where the button is located in the window
$CancelButton.Size = New-Object System.Drawing.Size(75,23) #Size -> defines the size of the button
$CancelButton.Text = "Cancel" #value -> sets the value of the button to 'Cancel'
$CancelButton.Add_Click({$objForm.Dispose(); exit}) #closing -> closes the window after clicked
$objForm.Controls.Add($CancelButton) #adding -> adds the button to the window
#ParID_Label -> creates a Label for the 'Par ID' input field
$ParIDLabel = New-Object System.Windows.Forms.Label #initialization -> initializes the label
$ParIDLabel.Location = New-Object System.Drawing.Size(10,10) #Location -> where the label is located in the window
$ParIDLabel.Size = New-Object System.Drawing.Size(280,20) #Size -> defines the size of the label
$ParIDLabel.Text = "Par ID (6 numbers!)" #value -> sets the value of the Label to 'Par ID (6 numbers)'
$objForm.Controls.Add($ParIDLabel) #adding -> adds the label to the window
#ParID Input Box -> Input box for the Par ID input
$ParIDInbox = New-Object System.Windows.Forms.TextBox #initialization -> initializes the input box
$ParIDInbox.Location = New-Object System.Drawing.Size(10,30) #Location -> where the label is located in the window
$ParIDInbox.Size = New-Object System.Drawing.Size(260,20) #Size -> defines the size of the inputbox
$ParIDInbox.MaxLength = 6 #sets max. length of the input box to 6
$objForm.Controls.Add($ParIDInbox) #adding -> adds the input box to the window
#Research Group Label -> creates a Label for the 'Research Group' input field
$ResearchGroupLabel = New-Object System.Windows.Forms.Label #initialization -> initializes the label
$ResearchGroupLabel.Location = New-Object System.Drawing.Size(10,50) #Location -> where the label is located in the window
$ResearchGroupLabel.Size = New-Object System.Drawing.Size(280,20) #Size -> defines the size of the label
$ResearchGroupLabel.Text = "Research Group (3 letters!)" #value -> sets the value of the Label to 'Research Group (3 letters!)'
$objForm.Controls.Add($ResearchGroupLabel) #adding -> adds the label to the window
#Research Group Input Box -> Input box for the Research Group input
$ResearchGroupInbox = New-Object System.Windows.Forms.ComboBox #initialization -> initializes the combobox (dropdown)
$ResearchGroupInbox.Location = New-Object System.Drawing.Size(10, 70) #Location -> where the dropdown is located in the window
$ResearchGroupInbox.Size = New-Object System.Drawing.Size(130,28) #Size -> defines the size of the box
$ResearchGroupInbox.MaxLength = 3 #sets max. length of the input box to 3
ForEach ($Item in $DropDownArray) { #loop -> put all variables from '$DropDownArray' into '$Item'
$ResearchGroupInbox.Items.Add($Item) #adder -> add '$Item' to the dropdown
}
$objForm.Controls.Add($ResearchGroupInbox) #adding -> add the dropdown to the window
#Customer Label -> creates a Label for the 'Customer' input field
$CustomerLabel = New-Object System.Windows.Forms.Label #initialization -> initializes the label
$CustomerLabel.Location = New-Object System.Drawing.Size(10,91.5) #Location -> where the label is located in the window
$CustomerLabel.Size = New-Object System.Drawing.Size(280,20) #Size -> defines the size of the label
$CustomerLabel.Text = "Customer" #value -> sets the value of the Label to 'Customer'
$objForm.Controls.Add($CustomerLabel) #adding -> adds the label to the window
#Customer Input Box -> Input box for the Customer input
$CustomerInbox = New-Object System.Windows.Forms.TextBox #initialization -> initializes the input box
$CustomerInbox.Location = New-Object System.Drawing.Size(10,110) #Location -> where the label is located in the window
$CustomerInbox.Size = New-Object System.Drawing.Size(260,20) #Size -> defines the size of the inputbox
$CustomerInbox.MaxLength = 50 #sets max. length of the input box to 50
$objForm.Controls.Add($CustomerInbox) #adding -> adds the input box to the window
#Projectname Label -> creates a Label for the 'Projectname' input field
$ProjectnameLabel = New-Object System.Windows.Forms.Label #initialization -> initializes the label
$ProjectnameLabel.Location = New-Object System.Drawing.Size(10,130) #Location -> where the label is located in the window
$ProjectnameLabel.Size = New-Object System.Drawing.Size(280,20) #Size -> defines the size of the label
$ProjectnameLabel.Text = "Projectname" #value -> sets the value of the Label to 'Projectname'
$objForm.Controls.Add($ProjectnameLabel) #adding -> adds the label to the window
#Projectname Input Box -> Input box for the Projectname input
$ProjectnameInbox = New-Object System.Windows.Forms.TextBox #initialization -> initializes the input box
$ProjectnameInbox.Location = New-Object System.Drawing.Size(10,150) #Location -> where the label is located in the window
$ProjectnameInbox.Size = New-Object System.Drawing.Size(260,20) #Size -> defines the size of the inputbox
$ProjectnameInbox.MaxLength = 50 #sets max. length of the input box to 50
$objForm.Controls.Add($ProjectnameInbox) #adding -> adds the input box to the window
$objForm.Topmost = $True #topmost -> A topmost form is a form that overlaps all the other (non-topmost!) forms!
$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
if($ParID -match "[1-999999]") { #Numbcheck -> check if ParID is a number
$temp = 1
} else {
$temp = 0
}
#directory names -> will be used for creating the directories below!
$main_folder = "//workspace.cee.xxxxxx.com@SSL/DavWWWRoot/content/00000100/Research/TestOffer/documents/" + $year + "\" + $ParID + "_" + $Research_Groups + "_" + $Customer + "_" + $Projectname
# above is the "root" folder for the following 4 directories
$offer_folder = $main_folder + "\130_Offer_Documents" #Offer Document -> the directory in which review01 can be found
$delivery_folder = $main_folder + "\140_Deliveries_signedContracts" #signed Contracts -> another folder
$order_folder = $main_folder + "\150_Orders_Contracts" #Orders Contracts -> another folder
$review01_folder = $main_folder + "\130_Offer_Documents\review01" #review_01 -> the sub-folder of Offer Document where the document are located
#local file -> called "temporary" which will be created to down- & upload files (without this one the script won't work!!!)
mkdir "C:/temporary" #C: -> it will be created on the partition called C:
#online files -> those files are created to have the same structure as in the template directory
#all 5 folder creations are above
mkdir $main_folder
mkdir $offer_folder
mkdir $delivery_folder
mkdir $order_folder
mkdir $review01_folder
#download location (Ethernet) -> says where the files are downloaded!
$reviewcomments = $fileurl + "uuu-1617-999999-01_Reviewkommentare.xlsx" #reviewcomments -> where this .xlsx file is located
$AVB_de = $fileurl + "CT_RDA-REE_AVB_intern_de.pdf" #AVB_de -> where AVB_de file is located
$AVB_en = $fileurl + "CT_RDA-REE_AVB_intern_en.pdf" #AVB_en -> where AVB_en file is located
$internal_project = $fileurl + "999999_internal_project_categorization_en.xlsm" #internal project -> where internal_project file is located
$classification_document = $fileurl + "999999_Klassifizierungsdokument_V1.0.docx" #classification -> where the classification file is located
#where the files (the ones above) should be stored -> in the temporary folder on your local hard drive (do not store it anywhere else!!!)
$review_download = "C:/temporary/uuu-1617-999999-01_Reviewkommentare.xlsx"
$AVB_de_download = "C:/temporary/CT_RDA-REE_AVB_intern_de.pdf"
$AVB_en_download = "C:/temporary/CT_RDA-REE_AVB_intern_en.pdf"
$internal_project_download = "C:/temporary/999999_internal_project_categorization_en.xlsx"
$classification_download = "C:/temporary/999999_Klassifizierungsdokument_V1.0.docx"
#actual Download -> here the files are downloaded using the webclient
#format -> $webclient.DownloadFile(webdownload, location on your pc)
$webclient.DownloadFile($reviewcomments, $review_download)
$webclient.DownloadFile($AVB_de, $AVB_de_download)
$webclient.DownloadFile($AVB_en, $AVB_en_download)
$webclient.DownloadFile($internal_project, $internal_project_download)
$webclient.DownloadFile($classification_document, $classification_download)
#webUrl -> the Url the files are copied to (the folder on the sharepoint) and during that they are renamed
$file = $internal_project_donwload
$webUrlbasic = "https://workspace.cee.xxxxx.com/content/00000100/Research/TestOffer/documents/" + $year + "/" + $ParID + "_" + $Research_Groups + "_" + $Customer + "_" + $Projectname + "/130_Offer_Documents/review01/"
$internal_project_Url = $webUrlbasic + $ParID + "_internal_project_categorization_en.xlsm"
$classification_Url = $webUrlbasic + $ParID + "_Klassifizierungsdokument_V1.0.docx"
$AVB_de_Url = $webUrlbasic + "CT_RDA-REE_AVB_intern_de.pdf"
$AVB_en_Url = $webUrlbasic + "CT_RDA-REE_AVB_intern_en.pdf"
$review_comment_Url = $webUrlbasic + $Research_Groups + "-" + $review_comments_year + "-" + $ParID + "-01_Review kommentare.xlsx"
#actual Upload -> here the files are uploaded using the webclient
#format -> $webclient.UploadFile(webupload, "PUT" ,location on your pc)
$webclient.UploadFile($internal_project_Url, "PUT", $internal_project_download)
$webclient.UploadFile($classification_Url, "PUT", $classification_download)
$webclient.UploadFile($AVB_de_Url, "PUT", $AVB_de_download)
$webclient.UploadFile($AVB_en_Url, "PUT", $AVB_en_download)
$webclient.UploadFile($review_comment_Url, "PUT", $review_download)
#remove -> removes the "temporary" folder which has been created for this script to work
Remove-Item "C:/temporary" -Recurse
#open browser -> opens the sharepoint site where the new files should have been created
$IE=new-object -com internetexplorer.application #launch internet explorer
$IE.navigate2("https://workspace.cee.xxxxxx.com/content/00000100/Research/TestOffer/documents/" + $year + "/" + $ParID + "_" + $Research_Groups + "_" + $Customer + "_" + $Projectname + "/130_Offer_Documents/review01/")
#get the website url (above)
$IE.visible=$true #show the site
编辑:我正在使用Powershell 2.0并且升级有点问题(因为我的公司)并且抱歉URL行中的xxxxxx但是我不允许显示... < / p>
巨大的编辑:我认识到我公司的powershell版本是1.0 sooo我认为我应该升级^^