Declaring inplacerecords

%3CLINGO-SUB%20id%3D%22lingo-sub-192402%22%20slang%3D%22en-US%22%3EDeclaring%20inplacerecords%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192402%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Guy's%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20got%20hold%20of%20a%20script%20and%20started%20customizing%20it%20how%20i%20would%20like.%20The%20script%20itself%20runs%20ok%20after%20some%20tweaks%2C%20and%20now%20i%20would%20like%20to%20make%20it%20do%20something%20else.%3C%2FP%3E%3CP%3EThe%20main%20part%20is%20supposed%20to%20iterate%20through%20all%20sites%20and%20subsites%20and%20their%20libraries%20and%20look%20for%20files%20that%20have%20the%20metdata%20column%20Colour%20and%20a%20value%20of%20Red.%20if%20so%20it%20copies%20the%20file%2Fs%20to%20a%20local%20structure%20in%20ntfs%20that%20replicates%20the%20SharePoint%20site%20collection.%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%2C%20i%20have%20added%20in%20another%20section%20whereby%20i%20am%20trying%20to%20identify%20the%20same%20files%2C%20and%20it%20checks%20if%20it%20is%20not%20already%20a%20record%20and%20if%20it%20is%20not%2C%20then%20declare%20it%20a%20record%20in%20the%20library...%3C%2FP%3E%3CP%3EBut%20it%20keeps%20erroring%20and%20doesn't%20make%20sense%20to%20me.%20I'm%20still%20learning%20to%20script%20so%20would%20be%20great%20for%20some%20help%20or%20pointers%20to%20understand%20the%20issue%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EScript%20and%20error%20below%3A%3C%2FP%3E%3CP%3E%3CSPAN%3EAdd-PSSnapin%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BMicrosoft.SharePoint.PowerShell%26nbsp%3B-erroraction%26nbsp%3B%22silentlycontinue%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%24exportPath%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BRead-Host%26nbsp%3B%22Enter%20the%20export%20location%20(eg.%20C%3A%5Cexport).%20This%20directory%20will%20be%20created%20if%20it%20doesn%E2%80%99t%20exist%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24URL%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BRead-Host%26nbsp%3B%22Enter%20the%20url%20from%20SharePoint%20(eg.%20%22%3CA%20href%3D%22https%3A%2F%2Fo%252A%252A%252A.ho%252A%252A%252A%252A.net%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2F***.****.net%3C%2FA%3E%22...https%3A%2F%2F***.****.net%2Fsites%2F..).%20This%20needs%20to%20be%20a%20site%20collection%20or%20web%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BdownloadFiles(%24OutputLocation%2C%26nbsp%3B%24url)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Create%20output%20folders%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24rootFolder%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24OutputLocation%26nbsp%3B%2B%26nbsp%3B%22%5C%24URL%22.Split(%22%2F%22)%5B-1%5D)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24errorFolder%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5CErrors%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24InplaceFolder%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5CInplace%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Create%20logging%20files%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24loggingFile%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5Clogging.csv%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24notDownloadedFile%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5CnotDownloaded.csv%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24errorFile%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5Cerrors.csv%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24InplaceloggingFile%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24InplaceFolder%26nbsp%3B%2B%26nbsp%3B%22%5CInplacelogging.csv%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24InplaceloggingFileErrors%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24InplaceFolder%26nbsp%3B%2B%26nbsp%3B%22%5CInplaceloggingErrors.csv%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Verify%20that%20the%20URL%20is%20a%20web%20in%20SharePoint%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23try%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23%24web%20%3D%20get-spweb%20%24url%20-erroraction%20%22silentlycontinue%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23%24web.dispose()%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22Update%3A%20Starting%20downloading%20specified%20web%22%26nbsp%3B-foregroundcolor%26nbsp%3Bgreen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Start%20download%20of%20specified%20url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EdownloadWeb%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24url%26nbsp%3B%24rootFolder%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23catch%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23write-host%20%22Error%3A%20URL%20is%20not%20a%20valid%20web%20in%20SharePoint%22%20-foregroundcolor%20red%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BcreateFolder(%24folderPath)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Create%20directory%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23first%20test%20if%20the%20directory%20is%20not%20longer%20then%20248%20characters.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24count%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24folderPath%26nbsp%3B%7C%26nbsp%3Bmeasure-object%26nbsp%3B-character%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%24count.characters%26nbsp%3B-le%26nbsp%3B247)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23verify%20if%20the%20path%20exists%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(!(Test-Path%26nbsp%3B-path%26nbsp%3B%24folderPath))%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ENew-Item%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24folderPath%26nbsp%3B-type%26nbsp%3Bdirectory%26nbsp%3B%7C%26nbsp%3BOut-Null%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22Folder%20created%3A%26nbsp%3B%24(%24folderPath)%22%26nbsp%3B-foregroundcolor%26nbsp%3Bgreen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eelse%7B%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22Folder%20already%20exists%2C%20trying%20to%20create%20a%20unique%20folder%20with%20random%20number%22%26nbsp%3B-foregroundcolor%26nbsp%3Byellow%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23create%20a%20random%20to%20add%20to%20the%20folder%20name%20because%20it%20already%20exists%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24randomNumber%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BGet-Random%26nbsp%3B-minimum%26nbsp%3B1%26nbsp%3B-maximum%26nbsp%3B10%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B((Test-Path%26nbsp%3B-path%26nbsp%3B%24errorFile)%26nbsp%3B-eq%26nbsp%3B%24true)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22Folder%3A%26nbsp%3B%24(%24folderPath)%26nbsp%3Balready%20exists%20and%20created%20a%20unique%20folder%20with%20number%26nbsp%3B%24(%24randomNumber)%22%26nbsp%3B-path%26nbsp%3B%24errorFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%24folderPath%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24folderPath%26nbsp%3B%2B%26nbsp%3B%24randomNumber)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eelse%7B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23create%20a%20folder%20under%20errors%20to%20download%20the%20files%20to%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22Foldername%20is%20to%20long%2C%20trying%20to%20create%20a%20folder%20under%20the%20errors%20folder%22%26nbsp%3B-foregroundcolor%26nbsp%3Byellow%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B((Test-Path%26nbsp%3B-path%26nbsp%3B%24errorFile)%26nbsp%3B-eq%26nbsp%3B%24true)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22Folder%3A%26nbsp%3B%24(%24folderPath)%26nbsp%3Bis%20to%20long%20and%20documents%20have%20been%20moved%20to%20the%20error%20folder%20under%26nbsp%3B%24SPWeb.Title%22%26nbsp%3B-path%26nbsp%3B%24errorFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%24folderpath%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24errorFolder%26nbsp%3B%2B%26nbsp%3B%22%5Csite-%22%26nbsp%3B%2B%26nbsp%3B%24SPWeb.Title%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ENew-Item%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24folderPath%26nbsp%3B-type%26nbsp%3Bdirectory%26nbsp%3B%7C%26nbsp%3Bout-null%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24folderPath%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BcreateFile(%24filePath)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Create%20file%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(!(Test-Path%26nbsp%3B-path%26nbsp%3B%24filePath))%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3ENew-Item%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24filePath%26nbsp%3B-type%26nbsp%3Bfile%26nbsp%3B%7C%26nbsp%3Bout-null%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22File%20created%3A%26nbsp%3B%24(%24filePath)%22%26nbsp%3B-foregroundcolor%26nbsp%3Bgreen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Eelse%7B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23add%20a%20number%20to%20the%20file%20name%20if%20it%20already%20exists%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22File%20already%20exists%2C%20trying%20to%20create%20a%20unique%20folder%20with%20random%20number%22%26nbsp%3B-foregroundcolor%26nbsp%3Byellow%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24randomNumber%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BGet-Random%26nbsp%3B-minimum%26nbsp%3B1%26nbsp%3B-maximum%26nbsp%3B100%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22File%3A%26nbsp%3B%24(%24filePath)%26nbsp%3Balready%20exists%20and%20created%20a%20unique%20file%20with%20number%24(%24randomNumber)%22%26nbsp%3B-path%26nbsp%3B%24errorFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24filePath%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFile%26nbsp%3B(%24filePath%26nbsp%3B%2B%26nbsp%3B%24randomNumber)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ereturn%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24filePath%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BdownloadWeb(%24startWeb%2C%26nbsp%3B%24rootFolder)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Get%20web%20information%20with%20PowerShell%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24SPWeb%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3Bget-spweb%26nbsp%3B%22%24startWeb%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Store%20the%20full%20sitefolder%20url%20in%20a%20variable%20and%20create%20the%20folder%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24siteFolder%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24rootFolder%26nbsp%3B%2B%26nbsp%3B%22%5Csite_%22%26nbsp%3B%2B%26nbsp%3B%24SPweb.Title)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Store%20the%20full%20url%20in%20a%20text%20file%20inside%20the%20folder%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24SPWeb%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Eurl%26nbsp%3B%7C%26nbsp%3Bout-file%26nbsp%3B-filepath%26nbsp%3B%24siteFolder%5CsiteURL.txt%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23System%20Libraries%20to%20exclude%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24systemList%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%40(%22Converted%20Forms%22%2C%22Master%20Page%20Gallery%22%2C%22Customized%20Reports%22%2C%22Form%20Templates%22%2C%22List%20Template%20Gallery%22%2C%22Theme%20Gallery%22%2C%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%22Reporting%20Templates%22%2C%22Solution%20Gallery%22%2C%22Style%20Library%22%2C%22Web%20Part%20Gallery%22%2C%22Site%20Assets%22%2C%22Site%20Pages%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Loop%20through%20all%20the%20document%20libraries%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E(%24list%26nbsp%3Bin%26nbsp%3B%24SPweb.lists)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E((%24list.BaseType%26nbsp%3B-eq%26nbsp%3B%22DocumentLibrary%22)%26nbsp%3B-and%26nbsp%3B(%24list.hidden%26nbsp%3B-eq%26nbsp%3B%24false)%26nbsp%3B-and%26nbsp%3B(%24systemList%26nbsp%3B-notcontains%26nbsp%3B%24list.title))%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Get%20root%20folder%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24listUrl%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24web.Url%26nbsp%3B%2B%22%2F%22%2B%26nbsp%3B%24list.RootFolder.Url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Download%20root%20files%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EdownloadLibrary%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24list.RootFolder.Url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Download%20files%20in%20folders%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%24folder%26nbsp%3Bin%26nbsp%3B%24list.Folders)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EdownloadLibrary%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24folder.Url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23add%20logging%20to%20show%20which%20webs%20have%20been%20touched%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22Downloaded%3A%26nbsp%3B%24(%24SPWeb.url)%22%26nbsp%3B-path%26nbsp%3B%24loggingFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Loop%20through%20each%20subsite%20of%20the%20web%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24SPWebs%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24SPWeb.webs%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E(%24SPweb%26nbsp%3Bin%26nbsp%3B%24SPwebs)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EdownloadWeb%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24SPweb.url%26nbsp%3B%24siteFolder%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%23dispose%20web%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24SPWeb%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Edispose()%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Efunction%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3BdownloadLibrary%26nbsp%3B(%24libraryURL)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Create%20folder%20based%20on%20document%20library%20name%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24SPLibrary%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24SPWeb.GetFolder(%24libraryURL)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24libraryFolder%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BcreateFolder%26nbsp%3B(%24siteFolder%26nbsp%3B%2B%26nbsp%3B%22%5Clib-%22%26nbsp%3B%2B%26nbsp%3B%24SPLibrary.url)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%24file%26nbsp%3Bin%26nbsp%3B%24SPLibrary.Files%26nbsp%3B%7C%26nbsp%3B%3F%7B%26nbsp%3B%24_.Item%5B%22Colour%22%5D%26nbsp%3B-eq%26nbsp%3B'Red'%26nbsp%3B%20%7D%20)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%24IsRecord%26nbsp%3B%3D%5BMicrosoft.Office.RecordsManagement.RecordsRepository.Records%5D%3A%3AIsRecord(%24file)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%24Filetype%26nbsp%3B%3D%26nbsp%3B%24file.FileSystemObjectType%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bif(%24Filetype%26nbsp%3B-eq%26nbsp%3B%22File%22)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Bif%26nbsp%3B(%24IsRecord%26nbsp%3B-ne%26nbsp%3B%24true)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3BWrite-Host%26nbsp%3B%22Declared%20for%20%22%26nbsp%3B%24file.DisplayName%26nbsp%3B-ForegroundColor%26nbsp%3BGreen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%5BMicrosoft.Office.RecordsManagement.RecordsRepository.Records%5D%3A%3ADeclareItemAsRecord(%24file)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%23add%20logging%20to%20show%20which%20webs%20have%20been%20touched%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3Badd-content%26nbsp%3B-value%26nbsp%3B%22Downloaded%3A%26nbsp%3B%24(%24File.Url)%22%26nbsp%3B-path%26nbsp%3B%24InplaceloggingFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ecatch%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24ErrorMessage%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24_.Exception.Message%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAdd-Content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-Path%26nbsp%3B%24InplaceloggingFileErrors%26nbsp%3B-Value%26nbsp%3B%24ErrorMessage%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWrite-Host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%24ErrorMessage%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24ErrorActionPreference%3C%2FSPAN%3E%3CSPAN%3E%3D%3C%2FSPAN%3E%3CSPAN%3E%22Stop%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EWrite-Host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22Downloading%20library%3A%26nbsp%3B%24(%24SPLibrary.name)%22%26nbsp%3B-foreground%26nbsp%3Bdarkgreen%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22Downloading%20library%3A%26nbsp%3B%24(%24SPLibrary.name)%22%26nbsp%3B-path%26nbsp%3B%24loggingFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%24file%26nbsp%3Bin%26nbsp%3B%24SPLibrary.Files%26nbsp%3B%7C%26nbsp%3B%3F%7B%26nbsp%3B%24_.Item%5B%22Colour%22%5D%26nbsp%3B-eq%26nbsp%3B'Red'%26nbsp%3B%20%7D%20)%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%23Download%20file%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Etry%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24binary%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3B%24file.OpenBinary()%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24stream%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BNew-Object%26nbsp%3BSystem.IO.FileStream(%24libraryFolder%26nbsp%3B%2B%26nbsp%3B%22%5C%22%26nbsp%3B%2B%26nbsp%3B%24file.Name)%2C%26nbsp%3BCreate%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24writer%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3D%26nbsp%3BNew-Object%26nbsp%3BSystem.IO.BinaryWriter(%24stream)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24writer%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3Ewrite(%24binary)%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%24writer%3C%2FSPAN%3E%3CSPAN%3E.%3C%2FSPAN%3E%3CSPAN%3EClose()%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ecatch%3C%2FSPAN%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Ewrite-host%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%22File%3A%26nbsp%3B%24(%24file.Name)%26nbsp%3Berror%22%26nbsp%3B-foregroundcolor%26nbsp%3Bred%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3Eadd-content%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-value%26nbsp%3B%22File%3A%26nbsp%3B%24(%24SPWeb.url)%26nbsp%3Bhas%20not%20been%20downloaded%22%26nbsp%3B-path%26nbsp%3B%24notDownloadedFile%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EdownloadFiles%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-OutputLocation%26nbsp%3B%24exportPath%26nbsp%3B-url%26nbsp%3B%24url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECannot%20convert%20argument%20%22item%22%2C%20with%20value%3A%20%22Team_Admin%2FDir%2Fxx_x_x%20-%20Laptop.msg%22%2C%20for%20%22IsRecord%22%20to%20type%20%22Microsoft.SharePoint.SPListItem%22%3A%20%22Cannot%3C%2FP%3E%3CP%3Econvert%20the%20%22Team_Admin%2FDir%2Fxx_x_x%20-%20Laptop.msg%22%20value%20of%20type%20%22Microsoft.SharePoint.SPFile%22%20to%20type%20%22Microsoft.SharePoint.SPListItem%22.%22%3C%2FP%3E%3CP%3EAt%20D%3A%5CAudit%20scripts%20to%20use%5CInplace-Extraction.ps1%3A130%20char%3A13%3C%2FP%3E%3CP%3E%2B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%24IsRecord%20%3D%20%5BMicrosoft.Office.RecordsManagement.RecordsRepository.Re%20...%3C%2FP%3E%3CP%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5B%5D%2C%20MethodException%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20MethodArgumentConversionInvalidCastArgument%3C%2FP%3E%3CP%3ECannot%20convert%20argument%20%22item%22%2C%20with%20value%3A%20%22Team_Admin%2FDir%2FLaptops%20-%20allocation%20details.xlsx%22%2C%20for%20%22IsRecord%22%20to%20type%20%22Microsoft.SharePoint.SPListItem%22%3A%20%22Cannot%20convert%20the%3C%2FP%3E%3CP%3E%22Team_Admin%2FDir%2FLaptops%20-%20allocation%20details.xlsx%22%20value%20of%20type%20%22Microsoft.SharePoint.SPFile%22%20to%20type%20%22Microsoft.SharePoint.SPListItem%22.%22%3C%2FP%3E%3CP%3EAt%20D%3A%5CAudit%20scripts%20to%20use%5CInplace-Extraction.ps1%3A130%20char%3A13%3C%2FP%3E%3CP%3E%2B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24IsRecord%20%3D%20%5BMicrosoft.Office.RecordsManagement.RecordsRepository.Re%20...%3C%2FP%3E%3CP%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3A%20NotSpecified%3A%20(%3A)%20%5B%5D%2C%20MethodException%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20MethodArgumentConversionInvalidCastArgument%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-193095%22%20slang%3D%22en-US%22%3ERe%3A%20Declaring%20inplacerecords%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-193095%22%20slang%3D%22en-US%22%3E%3CP%3ETry%20to%20see%20SharePointPnPPowerShell%20cmdlets%20there%20some%20to%20test%2C%20declare%20and%20undeclare%20item%20as%20records.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Visitor

Hi Guy's,

 

I have got hold of a script and started customizing it how i would like. The script itself runs ok after some tweaks, and now i would like to make it do something else.

The main part is supposed to iterate through all sites and subsites and their libraries and look for files that have the metdata column Colour and a value of Red. if so it copies the file/s to a local structure in ntfs that replicates the SharePoint site collection. 

However, i have added in another section whereby i am trying to identify the same files, and it checks if it is not already a record and if it is not, then declare it a record in the library...

But it keeps erroring and doesn't make sense to me. I'm still learning to script so would be great for some help or pointers to understand the issue?

 

Script and error below:

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction "silentlycontinue"

 

$exportPath = Read-Host "Enter the export location (eg. C:\export). This directory will be created if it doesn’t exist"

$URL = Read-Host "Enter the url from SharePoint (eg. "https://***.****.net"...https://***.****.net/sites/..). This needs to be a site collection or web"

 

function downloadFiles($OutputLocation, $url){

#Create output folders

$rootFolder = createFolder ($OutputLocation + "\$URL".Split("/")[-1])

$errorFolder = createFolder ($rootFolder + "\Errors")

$InplaceFolder = createFolder ($rootFolder + "\Inplace")

#Create logging files

$loggingFile = createFile ($rootFolder + "\logging.csv")

$notDownloadedFile = createFile ($rootFolder + "\notDownloaded.csv")

$errorFile = createFile ($rootFolder + "\errors.csv")

$InplaceloggingFile = createFile ($InplaceFolder + "\Inplacelogging.csv")

$InplaceloggingFileErrors = createFile ($InplaceFolder + "\InplaceloggingErrors.csv")

#Verify that the URL is a web in SharePoint

#try{

#$web = get-spweb $url -erroraction "silentlycontinue"

#$web.dispose()

write-host "Update: Starting downloading specified web" -foregroundcolor green

 

#Start download of specified url

downloadWeb $url $rootFolder

}

#catch{

#write-host "Error: URL is not a valid web in SharePoint" -foregroundcolor red

#}

#}

 

function createFolder($folderPath){

#Create directory

#first test if the directory is not longer then 248 characters.

$count = $folderPath | measure-object -character

 

if ($count.characters -le 247){

#verify if the path exists

if (!(Test-Path -path $folderPath)){

New-Item $folderPath -type directory | Out-Null

write-host "Folder created: $($folderPath)" -foregroundcolor green

}

else{

write-host "Folder already exists, trying to create a unique folder with random number" -foregroundcolor yellow

 

#create a random to add to the folder name because it already exists

$randomNumber = Get-Random -minimum 1 -maximum 10

if ((Test-Path -path $errorFile) -eq $true){

add-content -value "Folder: $($folderPath) already exists and created a unique folder with number $($randomNumber)" -path $errorFile

}

 

$folderPath = createFolder ($folderPath + $randomNumber)

}

}

else{

#create a folder under errors to download the files to

write-host "Foldername is to long, trying to create a folder under the errors folder" -foregroundcolor yellow

if ((Test-Path -path $errorFile) -eq $true){

add-content -value "Folder: $($folderPath) is to long and documents have been moved to the error folder under $SPWeb.Title" -path $errorFile

}

 

$folderpath = $errorFolder + "\site-" + $SPWeb.Title

New-Item $folderPath -type directory | out-null

}

return $folderPath

}

 

function createFile($filePath){

#Create file

if (!(Test-Path -path $filePath)){

New-Item $filePath -type file | out-null

write-host "File created: $($filePath)" -foregroundcolor green

}

else{

#add a number to the file name if it already exists

write-host "File already exists, trying to create a unique folder with random number" -foregroundcolor yellow

$randomNumber = Get-Random -minimum 1 -maximum 100

add-content -value "File: $($filePath) already exists and created a unique file with number$($randomNumber)" -path $errorFile

$filePath = createFile ($filePath + $randomNumber)

}

return $filePath

}

 

function downloadWeb($startWeb, $rootFolder){

#Get web information with PowerShell

$SPWeb = get-spweb "$startWeb"

 

#Store the full sitefolder url in a variable and create the folder

$siteFolder = createFolder ($rootFolder + "\site_" + $SPweb.Title)

 

#Store the full url in a text file inside the folder

$SPWeb.url | out-file -filepath $siteFolder\siteURL.txt

 

#System Libraries to exclude

$systemList = @("Converted Forms","Master Page Gallery","Customized Reports","Form Templates","List Template Gallery","Theme Gallery",

                "Reporting Templates","Solution Gallery","Style Library","Web Part Gallery","Site Assets","Site Pages")

 

#Loop through all the document libraries

foreach($list in $SPweb.lists){

if(($list.BaseType -eq "DocumentLibrary") -and ($list.hidden -eq $false) -and ($systemList -notcontains $list.title)){

#Get root folder

$listUrl = $web.Url +"/"+ $list.RootFolder.Url

#Download root files

downloadLibrary $list.RootFolder.Url

#Download files in folders

foreach ($folder in $list.Folders){

downloadLibrary $folder.Url

}

}

}

 

#add logging to show which webs have been touched

add-content -value "Downloaded: $($SPWeb.url)" -path $loggingFile

 

#Loop through each subsite of the web

$SPWebs = $SPWeb.webs

foreach($SPweb in $SPwebs){

downloadWeb $SPweb.url $siteFolder

}

 

#dispose web

$SPWeb.dispose()

}

 

function downloadLibrary ($libraryURL){

#Create folder based on document library name

$SPLibrary = $SPWeb.GetFolder($libraryURL)

$libraryFolder = createFolder ($siteFolder + "\lib-" + $SPLibrary.url)

foreach ($file in $SPLibrary.Files | ?{ $_.Item["Colour"] -eq 'Red'  } )

{

            $IsRecord =[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($file)

            $Filetype = $file.FileSystemObjectType

            if($Filetype -eq "File")

            {

                     if ($IsRecord -ne $true)

                     {

                     Write-Host "Declared for " $file.DisplayName -ForegroundColor Green

                    [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::DeclareItemAsRecord($file)

                     #add logging to show which webs have been touched

                     add-content -value "Downloaded: $($File.Url)" -path $InplaceloggingFile

catch{

$ErrorMessage = $_.Exception.Message

Add-Content -Path $InplaceloggingFileErrors -Value $ErrorMessage

Write-Host $ErrorMessage

$ErrorActionPreference="Stop"

}

}

}

}

Write-Host "Downloading library: $($SPLibrary.name)" -foreground darkgreen

add-content -value "Downloading library: $($SPLibrary.name)" -path $loggingFile

 

foreach ($file in $SPLibrary.Files | ?{ $_.Item["Colour"] -eq 'Red'  } ){

#Download file

try{

$binary = $file.OpenBinary()

$stream = New-Object System.IO.FileStream($libraryFolder + "\" + $file.Name), Create

$writer = New-Object System.IO.BinaryWriter($stream)

$writer.write($binary)

$writer.Close()

}

catch{

write-host "File: $($file.Name) error" -foregroundcolor red

add-content -value "File: $($SPWeb.url) has not been downloaded" -path $notDownloadedFile

}

}

}

 

 

 

 

downloadFiles -OutputLocation $exportPath -url $url

 

 

Cannot convert argument "item", with value: "Team_Admin/Dir/xx_x_x - Laptop.msg", for "IsRecord" to type "Microsoft.SharePoint.SPListItem": "Cannot

convert the "Team_Admin/Dir/xx_x_x - Laptop.msg" value of type "Microsoft.SharePoint.SPFile" to type "Microsoft.SharePoint.SPListItem"."

At D:\Audit scripts to use\Inplace-Extraction.ps1:130 char:13

+             $IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Re ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

Cannot convert argument "item", with value: "Team_Admin/Dir/Laptops - allocation details.xlsx", for "IsRecord" to type "Microsoft.SharePoint.SPListItem": "Cannot convert the

"Team_Admin/Dir/Laptops - allocation details.xlsx" value of type "Microsoft.SharePoint.SPFile" to type "Microsoft.SharePoint.SPListItem"."

At D:\Audit scripts to use\Inplace-Extraction.ps1:130 char:13

+             $IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Re ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodException

    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

1 Reply
Highlighted

Try to see SharePointPnPPowerShell cmdlets there some to test, declare and undeclare item as records.