Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$Network_Share_Folder = "\\dc1\AutopilotCSVs\"
$Folder = "C:\AutopilotCSVs"
$Exported_File = "C:\AutopilotCSVs\$env:computername.csv"
$Complete_User_Name = "deployment.mx\Administrator"
$Get_ExportHash_Status = $False
$Mapped_Drive_Status = $False
If(!(test-path $Folder))
{
new-item $Folder -type directory -force
write-host "The folder $Folder has been successfully created"
}
Try
{
$Creds = Get-Credential -Credential $Complete_User_Name
New-PSDrive -name "K" -PSProvider FileSystem -Root $Network_Share_Folder -Credential $Creds -ea silentlycontinue -ErrorVariable MappingError
$Mapped_Drive_Status = $True
}
Catch
{
write-warning "An issue occured during while exporting computer hash"
$MappingError
$Mapped_Drive_Status = $False
}
If ($Mapped_Drive_Status -eq $True)
{
Try
{
& "$Network_Share_Folder\Get-WindowsAutopilotInfo.ps1" -OutputFile $Exported_File
write-host "The computer hash has been exported in $Exported_File"
$Get_ExportHash_Status = $True
}
Catch
{
write-warning "An issue occured during while exporting computer hash"
}
}
If ($Get_ExportHash_Status -eq $True)
{
Try
{
copy-item $Exported_File $Network_Share_Folder
write-host "The file has been successfully saved on the network share"
$Get_Copy_Status = $True
}
Catch
{
write-warning "File can not be copied to the network share"
}
}
If ($Mapped_Drive_Status -eq $True)
{
If((Get-PSDrive -Name K -ErrorAction SilentlyContinue) -ne $null)
{
remove-psdrive -Name K -force
}
}
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.