Forum Discussion
vaibhavkaulkar
Sep 15, 2020Copper Contributor
Help....TAsk scheduler asking for credentials
Hi I have written a ps script to set retention policy for SP sites. Wheras the script works, I need to make it non interactive. Any help will be highly appreciated... ---------- Start-Transcript...
DeepakRandhawa
Sep 15, 2020Iron Contributor
Hello vaibhavkaulkar
Have you tried storing creds in an xml first, it is generally not a good idea to expose creds in the script.
If you want to try this, you can do below:-
-First store creds in an xml file
Get-Credential | Export-Clixml -Path "C:\Users\UserName\Desktop\Data\Cred.xml"
-Then Call them to connect your SP session
$Cred = (Import-Clixml "C:\Users\UserName\Desktop\Data\Cred.xml")
Connect-SPOService -Url $AdminURL -Credential $Cred
Hope this helps !!!
- vaibhavkaulkarSep 16, 2020Copper Contributor
DeepakRandhawa Thanks Deepak, I need to use this. So you mean- first time I set this up and then how do I read next time?
- DeepakRandhawaSep 16, 2020Iron Contributor
Hello vaibhavkaulkar,
Here's a step by step process:-
- First Open Powershell and use below cmdlet to generate an XML file with credentials:-
Get-Credential | Export-Clixml -Path "C:\Users\UserName\Desktop\Data\Cred.xmlWhen you will use this you will be prompted to enter your credentials, just enter your credentials in the pop up box that appears, once you do you will be able to see an XML file at the location provided in the above cmdlet in the -path parameter.
If you open the XML you will see that it contains your username in plain text and your password in encrypted text.
Please remember to generate the XML file with same User profile on the same Computer where you will be using them as credentials are encrypted using the Windows Data Protection API and can only be used by user who generated them and on the computer on which they were generated.
- Second step is to start you SP script with below cmdlets :-
Start-Transcript
Import-Module Microsoft.Online.SharePoint.Powershell -DisableNameChecking
Import-Module ExchangeOnlineManagement$Cred = (Import-Clixml "C:\Users\UserName\Desktop\Data\Cred.xml")
$AdminCenterURL = "https://xyz-admin.sharepoint.com/"
Connect-SPOService -Url $AdminURL -Credential $Cred
Connect-IPPSSession -Credential $Cred#create temp folder if it does not exist
$ReportOutput="C:\Temp\pvtSiteColl.csv"
#Get All site collections
........Thanks
- vaibhavkaulkarSep 23, 2020Copper Contributor
Hello DeepakRandhawa,
I still get a pop up to enter credentials.