শংসাপত্র সংরক্ষণ করার বিষয়ে, আমি দুটি ফাংশন ব্যবহার করি (এটি সাধারণত আমার মডিউল থেকে লোড হওয়া মডিউলে থাকে):
#=====================================================================
# Get-MyCredential
#=====================================================================
function Get-MyCredential
{
param(
$CredPath,
[switch]$Help
)
$HelpText = @"
Get-MyCredential
Usage:
Get-MyCredential -CredPath `$CredPath
If a credential is stored in $CredPath, it will be used.
If no credential is found, Export-Credential will start and offer to
Store a credential at the location specified.
"@
if($Help -or (!($CredPath))){write-host $Helptext; Break}
if (!(Test-Path -Path $CredPath -PathType Leaf)) {
Export-Credential (Get-Credential) $CredPath
}
$cred = Import-Clixml $CredPath
$cred.Password = $cred.Password | ConvertTo-SecureString
$Credential = New-Object System.Management.Automation.PsCredential($cred.UserName, $cred.Password)
Return $Credential
}
এবং এটি:
#=====================================================================
# Export-Credential
# Usage: Export-Credential $CredentialObject $FileToSaveTo
#=====================================================================
function Export-Credential($cred, $path) {
$cred = $cred | Select-Object *
$cred.password = $cred.Password | ConvertFrom-SecureString
$cred | Export-Clixml $path
}
আপনি এটি এর মতো ব্যবহার করুন:
$Credentials = Get-MyCredential (join-path ($PsScriptRoot) Syncred.xml)
যদি শংসাপত্রের ফাইলটি উপস্থিত না থাকে তবে আপনাকে প্রথমবারের জন্য অনুরোধ জানানো হবে, সেই সময়ে এটি কোনও এক্সএমএল ফাইলের ভিতরে একটি এনক্রিপ্ট করা স্ট্রিংয়ে শংসাপত্রগুলি সংরক্ষণ করবে। দ্বিতীয়বার আপনি এই লাইনটি চালাবেন, xmlfile আছে এবং স্বয়ংক্রিয়ভাবে খোলা হবে।