SOLVED
Home

Powershell script fo deleting specific-files-from-sharepoint-on-premises-library error

%3CLINGO-SUB%20id%3D%22lingo-sub-279360%22%20slang%3D%22en-US%22%3EPowershell%20script%20fo%20deleting%20specific-files-from-sharepoint-on-premises-library%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-279360%22%20slang%3D%22en-US%22%3E%3CDIV%3EI%20was%20going%20through%20article%3A%26nbsp%3B%3CA%20href%3D%22http%3A%2F%2Fromeodonca.com%2Fdeleting-specific-files-from-sharepoint-on-premises-library%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fromeodonca.com%2Fdeleting-specific-files-from-sharepoint-on-premises-library%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3EI%20am%20getting%20an%20issue%20in%20implementing%20it.%20can%20you%20please%20have%20a%20look%20intothe%20following%20scenario%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3BI%20tried%20the%201st%20script.%20it%20runs%20successfully%20however%20the%20files%20dont%20get%20deleted.%3C%2FDIV%3E%3CDIV%3Efor%20eg%3A%3C%2FDIV%3E%3CDIV%3Emy%20Site%20URL%3A%20%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3ELibrary%20name%3A%20library%3C%2FDIV%3E%3CDIV%3EFilename%3A%20test%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EIf%20you%20open%20my%20csv%20file%2C%20you%20will%20see%20the%20following%20list%20of%20URL's%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy.txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document.txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(2).txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(2).txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(3).txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(3).txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EPlease%20let%20me%20know%20whether%20I%20have%20to%20insert%20any%20column%20title%20in%20the%20csv%20or%20the%20above%20is%20just%20fine%3F%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3ESo%20My%20first%20script%20becomes%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Eparam(%3C%2FDIV%3E%3CDIV%3E%5BParameter(Mandatory%3D%24true%2CHelpMessage%3D%E2%80%9D%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%E2%80%9D)%5D%5Bstring%5D%24SiteUrl%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%E2%80%9D)%5D%5Bstring%5D%24SiteUrl%3C%2FA%3E%2C%3C%2FDIV%3E%3CDIV%3E%5BParameter(Mandatory%3D%24true%2CHelpMessage%3D%E2%80%9Dlibrary%E2%80%9D)%5D%5Bstring%5D%24LibraryName%2C%3C%2FDIV%3E%3CDIV%3E%5BParameter(Mandatory%3D%24true%2CHelpMessage%3D%E2%80%9Dtest%E2%80%9D)%5D%5Bstring%5D%24Filename%3C%2FDIV%3E%3CDIV%3E)%3C%2FDIV%3E%3CDIV%3EAdd-PSSnapin%20microsoft.sharepoint.powershell%3C%2FDIV%3E%3CDIV%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20parse%20all%20items%3C%2FDIV%3E%3CDIV%3Efunction%20deleting(%24mylist%2C%24yoursourcefile)%3C%2FDIV%3E%3CDIV%3E%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%24files%20%3D%20%40()%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20foreach%20(%24searchedfile%20in%20(Import-Csv%20%24yoursourcefile))%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%23%24myweb%20%3D%20get-spweb%20((%24searchedfile.url).split(%E2%80%98%2F%E2%80%99)%5B0%5D%2B%E2%80%9D%2F%2F%E2%80%9D%2B%24searchedfile.url.split(%E2%80%98%2F%E2%80%99)%5B2%5D)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%23%24mylist%20%3D%20%24myweb.Lists%20%7C%20Where-Object%20%7B%24_.Title%20-match%20(%24searchedfile.url).split(%E2%80%98%2F%E2%80%99)%5B3%5D%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20foreach%20(%24file%20in%20%24mylist.items)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20if%20((%24searchedfile.url)%20-eq%20((%24searchedfile.url).split(%E2%80%98%2F%E2%80%99)%5B0%5D%2B%E2%80%9D%2F%2F%E2%80%9D%2B(%24searchedfile.url).split(%E2%80%98%2F%E2%80%99)%5B2%5D%2B%E2%80%9D%2F%E2%80%9D%2B%24file.url))%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%E2%80%9CDeleting%3A%20%E2%80%9D%20%2B%26nbsp%3B%20%24searchedfile.url%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24files%20%3D%20%24files%20%2B%20%24file%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20break%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20foreach%20(%24item%20in%20%24files)%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%24item.Delete()%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%7D%3C%2FDIV%3E%3CDIV%3E%7D%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Ethe%20above%20script%20runs%20however%20the%20files%20dont%20get%20deleted.%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EI%20am%20not%20sure%20What%20wrong.%3C%2FDIV%3E%3CDIV%3EI%20tried%20doing%20the%20CAML%20Query.%3C%2FDIV%3E%3CDIV%3EAnd%20I%20get%20the%20following%20errors%20with%20different%20inputs%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E1)%26gt%3B%26gt%3B%26gt%3B%26gt%3BYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3C%2FDIV%3E%3CDIV%3EAt%20line%3A13%20char%3A9%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%24file%20%3D%20%24mylist.GetItems(%24query)%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E2)%26gt%3B%26gt%3B%26gt%3B%26gt%3B%26gt%3BYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3C%2FDIV%3E%3CDIV%3EAt%20line%3A18%20char%3A9%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%24item.Delete()%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B~~~~~~~~~~~~~~%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E3)%26gt%3B%26gt%3B%26gt%3B%26gt%3B%26gt%3Bdeleting%20%3A%20The%20term%20'deleting'%20is%20not%20recognized%20as%20the%20name%20of%20a%20cmdlet%2C%3C%2FDIV%3E%3CDIV%3Efunction%2C%20script%20file%2C%20or%20operable%20program.%20Check%20the%20spelling%20of%20the%20name%2C%20or%3C%2FDIV%3E%3CDIV%3Eif%20a%20path%20was%20included%2C%20verify%20that%20the%20path%20is%20correct%20and%20try%20again.%3C%2FDIV%3E%3CDIV%3EAt%20line%3A39%20char%3A21%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bdeleting%20%24mylist%20%24filename%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B~~~~~~~~%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3A%20ObjectNotFound%3A%20(deleting%3AString)%20%5B%5D%2C%20CommandNot%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3BFoundException%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20CommandNotFoundException%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E4)%26gt%3B%26gt%3B%26gt%3B%26gt%3BImport-Csv%20%3A%20Cannot%20validate%20argument%20on%20parameter%20'Path'.%20The%20argument%20is%3C%2FDIV%3E%3CDIV%3Enull%20or%20empty.%20Provide%20an%20argument%20that%20is%20not%20null%20or%20empty%2C%20and%20then%20try%20the%3C%2FDIV%3E%3CDIV%3Ecommand%20again.%3C%2FDIV%3E%3CDIV%3EAt%20line%3A4%20char%3A43%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3Bforeach%20(%24searchedfile%20in%20(Import-Csv%20%24test))%3C%2FDIV%3E%3CDIV%3E%2B%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B~~~~%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20CategoryInfo%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%3A%20InvalidData%3A%20(%3A)%20%5BImport-Csv%5D%2C%20ParameterBindingV%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3BalidationException%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3B%20%2B%20FullyQualifiedErrorId%20%3A%20ParameterArgumentValidationError%2CMicrosoft.Power%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%20%26nbsp%3BShell.Commands.ImportCsvCommand%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3ECan%20you%20please%20help%20me%20out%20in%20this.%20i%20am%20not%20sure%20what%20I%20am%20missing.%20How%20will%20the%20script%20turn%20out%20if%20I%20have%20the%20following%20inputs%20with%20me%3A%3C%2FDIV%3E%3CDIV%3E%3CDIV%3Emy%20Site%20URL%3A%20%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3ELibrary%20name%3A%20library%3C%2FDIV%3E%3CDIV%3EFilename%3A%20test%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3Ecsv%20file%3A%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy.txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document.txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document.txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(2).txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(2).txt%3C%2FA%3E%3C%2FDIV%3E%3CDIV%3E%3CA%20href%3D%22http%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(3).txt%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fcontoso.com%2Fsubsitename%2Flibrary%2FNew%2520Text%2520Document%2520-%2520Copy%2520(3).txt%3C%2FA%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3EI%20would%20really%20appreciate%20help%20on%20this!!%20thanks%20again%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-279360%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E2013%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDocument%20Library%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFiles%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Esharepoint%202013%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESites%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EUsage%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-280731%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20fo%20deleting%20specific-files-from-sharepoint-on-premises-library%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-280731%22%20slang%3D%22en-US%22%3E%3CP%3E%3CBR%20%2F%3EThank%20you%20so%20much%26nbsp%3B%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F177418%22%20target%3D%22_blank%22%3E%40Matt%20Weston%3C%2FA%3E!!%20I%20was%20missing%20the%20header.%20You%20made%20my%20day!!%3C%2FP%3E%3CP%3EI%20was%20cramming%20my%20head%20on%20this%20for%203%20days.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-280262%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20fo%20deleting%20specific-files-from-sharepoint-on-premises-library%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-280262%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F163419%22%20target%3D%22_blank%22%3E%40Test%20SharePoint%3C%2FA%3E%26nbsp%3Bthe%20way%20those%20errors%20are%20cascading%2C%20I%20think%20it's%20purely%20down%20to%20the%20entries%20that%20are%20coming%20from%20the%20CSV%2C%20and%20that%20all%20of%20the%20other%20errors%20are%20as%20a%20result%20of%20single%20issue.%20Do%20you%20have%20a%20header%20in%20your%20CSV%3F%20In%20mine%2C%20I%20had%20a%20header%20of%20File%2C%20so%20my%20CSV%20looked%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFile%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FSiteA%2FDocuments%2FFile1.docx%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FSiteA%2FDocuments%2FFile1.docx%3C%2FA%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FSiteA%2FDocuments%2FFile1%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcontoso.sharepoint.com%2Fsites%2FSiteA%2FDocuments%2FFile1%3C%2FA%3E%20Copy.docx%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-279717%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20fo%20deleting%20specific-files-from-sharepoint-on-premises-library%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-279717%22%20slang%3D%22en-US%22%3E%3CP%3Ethank%20you%20so%20much%20for%20your%20reply%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F177418%22%20target%3D%22_blank%22%3E%40Matt%20Weston%3C%2FA%3E.%20looks%20simplified%20now.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EI%20ran%20the%20following%20script%3A%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20SET%20UP%3C%2FP%3E%3CP%3EAdd-PSSnapin%20%22Microsoft.SharePoint.PowerShell%22%20-ErrorAction%20SilentlyContinue%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECLS%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20PULL%20IN%20THE%20CSV%3C%2FP%3E%3CP%3E%24filelist%20%3D%20Import-Csv%20-Path%20%22C%3A%5Ctemp%22%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%3Eforeach(%24file%20in%20%24filelist)%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E%26nbsp%3BWrite-Host%20%22Processing%20%24(%24file.File)%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Figure%20out%20the%20URL%20of%20the%20site%3C%2FP%3E%3CP%3E%26nbsp%3B%24arysiteurl%20%3D%20%24file.File.Split('%2F')%3C%2FP%3E%3CP%3E%26nbsp%3B%24url%20%3D%20%22%22%3C%2FP%3E%3CP%3E%26nbsp%3Bfor(%24x%3D0%3B%20%24x%20-lt%20%24arysiteurl.Length-2%3B%20%24x%2B%2B)%3C%2FP%3E%3CP%3E%26nbsp%3B%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%24url%20%3D%20%24url%20%2B%20%24arysiteurl%5B%24x%5D%20%2B%20%22%2F%22%3C%2FP%3E%3CP%3E%26nbsp%3B%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Get%20the%20web%3C%2FP%3E%3CP%3E%26nbsp%3B%24web%20%3D%20Get-SPWeb%20%24url%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20Get%20the%20document%20based%20on%20the%20URL%3C%2FP%3E%3CP%3E%26nbsp%3B%24file%20%3D%20%24web.GetFile(%24file.File)%3C%2FP%3E%3CP%3E%26nbsp%3B%24file.Delete()%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20get%20the%20following%20error%3A%3C%2FP%3E%3CP%3EProcessing%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A16%20char%3A2%3CBR%20%2F%3E%2B%20%24arysiteurl%20%3D%20%24file.File.Split('%2F')%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EGet-SPWeb%20%3A%20Cannot%20find%20an%20SPSite%20object%20that%20contains%20the%20following%20Id%20or%20Url%3A%20Empty%20or%20Null.%3CBR%20%2F%3EAt%20line%3A24%20char%3A9%3CBR%20%2F%3E%2B%20%24web%20%3D%20Get-SPWeb%20%24url%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidData%3A%20(Microsoft.Share....SPCmdletGetWeb%3ASPCmdletGetWeb)%20%5BGet-SPWeb%5D%2C%20SPCmdletPipeBindException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20Microsoft.SharePoint.PowerShell.SPCmdletGetWeb%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A27%20char%3A2%3CBR%20%2F%3E%2B%20%24file%20%3D%20%24web.GetFile(%24file.File)%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EMethod%20invocation%20failed%20because%20%5BSystem.Management.Automation.PSCustomObject%5D%20doesn't%20contain%20a%20method%20named%20'Delete'.%3CBR%20%2F%3EAt%20line%3A28%20char%3A2%3CBR%20%2F%3E%2B%20%24file.Delete()%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(Delete%3AString)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20MethodNotFound%3CBR%20%2F%3E%3CBR%20%2F%3EProcessing%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A16%20char%3A2%3CBR%20%2F%3E%2B%20%24arysiteurl%20%3D%20%24file.File.Split('%2F')%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EGet-SPWeb%20%3A%20Cannot%20find%20an%20SPSite%20object%20that%20contains%20the%20following%20Id%20or%20Url%3A%20Empty%20or%20Null.%3CBR%20%2F%3EAt%20line%3A24%20char%3A9%3CBR%20%2F%3E%2B%20%24web%20%3D%20Get-SPWeb%20%24url%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidData%3A%20(Microsoft.Share....SPCmdletGetWeb%3ASPCmdletGetWeb)%20%5BGet-SPWeb%5D%2C%20SPCmdletPipeBindException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20Microsoft.SharePoint.PowerShell.SPCmdletGetWeb%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A27%20char%3A2%3CBR%20%2F%3E%2B%20%24file%20%3D%20%24web.GetFile(%24file.File)%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EMethod%20invocation%20failed%20because%20%5BSystem.Management.Automation.PSCustomObject%5D%20doesn't%20contain%20a%20method%20named%20'Delete'.%3CBR%20%2F%3EAt%20line%3A28%20char%3A2%3CBR%20%2F%3E%2B%20%24file.Delete()%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(Delete%3AString)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20MethodNotFound%3CBR%20%2F%3E%3CBR%20%2F%3EProcessing%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A16%20char%3A2%3CBR%20%2F%3E%2B%20%24arysiteurl%20%3D%20%24file.File.Split('%2F')%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EGet-SPWeb%20%3A%20Cannot%20find%20an%20SPSite%20object%20that%20contains%20the%20following%20Id%20or%20Url%3A%20Empty%20or%20Null.%3CBR%20%2F%3EAt%20line%3A24%20char%3A9%3CBR%20%2F%3E%2B%20%24web%20%3D%20Get-SPWeb%20%24url%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidData%3A%20(Microsoft.Share....SPCmdletGetWeb%3ASPCmdletGetWeb)%20%5BGet-SPWeb%5D%2C%20SPCmdletPipeBindException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20Microsoft.SharePoint.PowerShell.SPCmdletGetWeb%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20cannot%20call%20a%20method%20on%20a%20null-valued%20expression.%3CBR%20%2F%3EAt%20line%3A27%20char%3A2%3CBR%20%2F%3E%2B%20%24file%20%3D%20%24web.GetFile(%24file.File)%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(%3A)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20InvokeMethodOnNull%3CBR%20%2F%3E%3CBR%20%2F%3EMethod%20invocation%20failed%20because%20%5BSystem.Management.Automation.PSCustomObject%5D%20doesn't%20contain%20a%20method%20named%20'Delete'.%3CBR%20%2F%3EAt%20line%3A28%20char%3A2%3CBR%20%2F%3E%2B%20%24file.Delete()%3CBR%20%2F%3E%2B%20~~~~~~~~~~~~~~%3CBR%20%2F%3E%2B%20CategoryInfo%20%3A%20InvalidOperation%3A%20(Delete%3AString)%20%5B%5D%2C%20RuntimeException%3CBR%20%2F%3E%2B%20FullyQualifiedErrorId%20%3A%20MethodNotFound%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%3EI%20am%20not%20sure%20what%20I%20am%20missing.%20Can%20you%20please%20help%20me%20out%20on%20this%20one%3F%3C%2FP%3E%3CP%3EMy%20website%20URL%3A%20http%3A%2Fcontoso%2Fsubsitename%3C%2FP%3E%3CP%3EMy%20Document%20library%20name%3A%20test%3C%2FP%3E%3CP%3EMy%20csv%20file%3A%20sha.csv%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-279450%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20script%20fo%20deleting%20specific-files-from-sharepoint-on-premises-library%20error%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-279450%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F163419%22%20target%3D%22_blank%22%3E%40Test%20SharePoint%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMost%20of%20the%20errors%20that%20you're%20encountering%20are%20caused%20by%20one%20part%20of%20your%20script%20failing%2C%20and%20therefore%20you%20have%20a%20number%20of%20null%20values%20being%20encountered.%26nbsp%3B%20To%20be%20honest%20you%20could%20probably%20simplify%20the%20script%20a%20lot%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%23%20SET%20UP%3CBR%20%2F%3EAdd-PSSnapin%20%22Microsoft.SharePoint.PowerShell%22%20-ErrorAction%20SilentlyContinue%3CBR%20%2F%3E%3CBR%20%2F%3ECLS%3CBR%20%2F%3E%3CBR%20%2F%3E%23%20PULL%20IN%20THE%20CSV%3CBR%20%2F%3E%24filelist%20%3D%20Import-Csv%20-Path%20%22%3CPATH%20to%3D%22%22%20the%3D%22%22%20csv%3D%22%22%3E%22%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3Eforeach(%24file%20in%20%24filelist)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%20Write-Host%20%22Processing%20%24(%24file.File)%22%3CBR%20%2F%3E%3CBR%20%2F%3E%23%20Figure%20out%20the%20URL%20of%20the%20site%3CBR%20%2F%3E%20%24arysiteurl%20%3D%20%24file.File.Split('%2F')%3CBR%20%2F%3E%20%24url%20%3D%20%22%22%3CBR%20%2F%3E%20for(%24x%3D0%3B%20%24x%20-lt%20%24arysiteurl.Length-2%3B%20%24x%2B%2B)%3CBR%20%2F%3E%20%7B%3CBR%20%2F%3E%20%24url%20%3D%20%24url%20%2B%20%24arysiteurl%5B%24x%5D%20%2B%20%22%2F%22%3CBR%20%2F%3E%20%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%23%20Get%20the%20web%3CBR%20%2F%3E%20%24web%20%3D%20Get-SPWeb%20%24url%3CBR%20%2F%3E%3CBR%20%2F%3E%23%20Get%20the%20document%20based%20on%20the%20URL%3CBR%20%2F%3E%20%24file%20%3D%20%24web.GetFile(%24file.File)%3CBR%20%2F%3E%20%24file.Delete()%3CBR%20%2F%3E%3CBR%20%2F%3E%7D%3C%2FPATH%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Test SharePoint
Contributor
I am getting an issue in implementing it. can you please have a look intothe following scenario:
 
 I tried the 1st script. it runs successfully however the files dont get deleted.
for eg:
Library name: library
Filename: test
 
 
If you open my csv file, you will see the following list of URL's:
 
 
 
Please let me know whether I have to insert any column title in the csv or the above is just fine?
 
 
So My first script becomes:
 
param(
[Parameter(Mandatory=$true,HelpMessage=”http://contoso.com/subsitename”)][string]$SiteUrl,
[Parameter(Mandatory=$true,HelpMessage=”library”)][string]$LibraryName,
[Parameter(Mandatory=$true,HelpMessage=”test”)][string]$Filename
)
Add-PSSnapin microsoft.sharepoint.powershell
###################################### parse all items
function deleting($mylist,$yoursourcefile)
{
    $files = @()
    foreach ($searchedfile in (Import-Csv $yoursourcefile))
    {
        #$myweb = get-spweb (($searchedfile.url).split(‘/’)[0]+”//”+$searchedfile.url.split(‘/’)[2])
        #$mylist = $myweb.Lists | Where-Object {$_.Title -match ($searchedfile.url).split(‘/’)[3]}
        foreach ($file in $mylist.items)
        {
            if (($searchedfile.url) -eq (($searchedfile.url).split(‘/’)[0]+”//”+($searchedfile.url).split(‘/’)[2]+”/”+$file.url))
            {
                “Deleting: ” +  $searchedfile.url
                $files = $files + $file
                break
            }
        }
    }
    foreach ($item in $files)
    {
        $item.Delete()
    }
}
 
 
 
the above script runs however the files dont get deleted.
 
I am not sure What wrong.
I tried doing the CAML Query.
And I get the following errors with different inputs:
 
1)>>>>You cannot call a method on a null-valued expression.
At line:13 char:9
+         $file = $mylist.GetItems($query)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
 
2)>>>>>You cannot call a method on a null-valued expression.
At line:18 char:9
+         $item.Delete()
+         ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
 
 
3)>>>>>deleting : The term 'deleting' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:39 char:21
+                     deleting $mylist $filename
+                     ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (deleting:String) [], CommandNot
   FoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
 
4)>>>>Import-Csv : Cannot validate argument on parameter 'Path'. The argument is
null or empty. Provide an argument that is not null or empty, and then try the
command again.
At line:4 char:43
+     foreach ($searchedfile in (Import-Csv $test))
+                                           ~~~~
    + CategoryInfo          : InvalidData: (:) [Import-Csv], ParameterBindingV
   alidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
   Shell.Commands.ImportCsvCommand
 
 
 
 
 
 
 
 
Can you please help me out in this. i am not sure what I am missing. How will the script turn out if I have the following inputs with me:
Library name: library
Filename: test
 
 
csv file:
 
 
 
I would really appreciate help on this!! thanks again
4 Replies
Highlighted

Hi @Test SharePoint

 

Most of the errors that you're encountering are caused by one part of your script failing, and therefore you have a number of null values being encountered.  To be honest you could probably simplify the script a lot

 

# SET UP
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

CLS

# PULL IN THE CSV
$filelist = Import-Csv -Path "<PATH TO THE CSV>"



foreach($file in $filelist)
{
Write-Host "Processing $($file.File)"

# Figure out the URL of the site
$arysiteurl = $file.File.Split('/')
$url = ""
for($x=0; $x -lt $arysiteurl.Length-2; $x++)
{
$url = $url + $arysiteurl[$x] + "/"
}

# Get the web
$web = Get-SPWeb $url

# Get the document based on the URL
$file = $web.GetFile($file.File)
$file.Delete()

}
Highlighted

thank you so much for your reply @Matt Weston. looks simplified now.

 

I ran the following script:

 

# SET UP

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

 

CLS

 

# PULL IN THE CSV

$filelist = Import-Csv -Path "C:\temp"

 

 

 

foreach($file in $filelist)

{

 Write-Host "Processing $($file.File)"

 

# Figure out the URL of the site

 $arysiteurl = $file.File.Split('/')

 $url = ""

 for($x=0; $x -lt $arysiteurl.Length-2; $x++)

 {

 $url = $url + $arysiteurl[$x] + "/"

 }

 

# Get the web

 $web = Get-SPWeb $url

 

# Get the document based on the URL

 $file = $web.GetFile($file.File)

 $file.Delete()

 

}

 

I get the following error:

Processing
You cannot call a method on a null-valued expression.
At line:16 char:2
+ $arysiteurl = $file.File.Split('/')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url: Empty or Null.
At line:24 char:9
+ $web = Get-SPWeb $url
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb

You cannot call a method on a null-valued expression.
At line:27 char:2
+ $file = $web.GetFile($file.File)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [System.Management.Automation.PSCustomObject] doesn't contain a method named 'Delete'.
At line:28 char:2
+ $file.Delete()
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Processing
You cannot call a method on a null-valued expression.
At line:16 char:2
+ $arysiteurl = $file.File.Split('/')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url: Empty or Null.
At line:24 char:9
+ $web = Get-SPWeb $url
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb

You cannot call a method on a null-valued expression.
At line:27 char:2
+ $file = $web.GetFile($file.File)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [System.Management.Automation.PSCustomObject] doesn't contain a method named 'Delete'.
At line:28 char:2
+ $file.Delete()
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Processing
You cannot call a method on a null-valued expression.
At line:16 char:2
+ $arysiteurl = $file.File.Split('/')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Get-SPWeb : Cannot find an SPSite object that contains the following Id or Url: Empty or Null.
At line:24 char:9
+ $web = Get-SPWeb $url
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletGetWeb:SPCmdletGetWeb) [Get-SPWeb], SPCmdletPipeBindException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletGetWeb

You cannot call a method on a null-valued expression.
At line:27 char:2
+ $file = $web.GetFile($file.File)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Method invocation failed because [System.Management.Automation.PSCustomObject] doesn't contain a method named 'Delete'.
At line:28 char:2
+ $file.Delete()
+ ~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Delete:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

 

 

 

I am not sure what I am missing. Can you please help me out on this one?

My website URL: http:/contoso/subsitename

My Document library name: test

My csv file: sha.csv

 

Highlighted
Solution

Hi @Test SharePoint the way those errors are cascading, I think it's purely down to the entries that are coming from the CSV, and that all of the other errors are as a result of single issue. Do you have a header in your CSV? In mine, I had a header of File, so my CSV looked like this:

 

File

https://contoso.sharepoint.com/sites/SiteA/Documents/File1.docx

https://contoso.sharepoint.com/sites/SiteA/Documents/File1 Copy.docx

Highlighted


Thank you so much  @Matt Weston!! I was missing the header. You made my day!!

I was cramming my head on this for 3 days.

Related Conversations
IOWSPostData Failed
MMMZ14 in SharePoint on
0 Replies
Sharepoint and Onedrive Access
DavidYorkshire in Office 365 on
4 Replies
outlook 365 endless synchronizing
James_22 in Office 365 on
0 Replies
"You frequently open this" issue
AhmedAliAwed94 in Office 365 on
0 Replies