I am creating a script to:
- Create a directory in Program Files
- Copy a XML file from TFTP server to the newly created directory
- Run the XML
md "\Program Files\Test" -Credential Get-Credential md : The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying credentials.My Full Script:
$host.UI.RawUI.WindowTitle = "XMLTestFile1" $sourcePath = "\\TFTPServer\Folderlocation\Filename.xml" $destPath = "\Program Files\TestFile1" $File = "\Program Files\Test\Filename.xml"Write-Host “Local File NOT Found … Copying Files & Starting Filename.xml”
$UserName = Read-Host ‘Please enter your AD Username’
md -Path “\Program Files\Test” -Credential (Get-Credential -Username “$ENV:UserDomain$UserName” -Message ‘Enter your password’)
Start-BitsTransfer -Source $sourcePath -Destination $destPath
Start-Process $File -ErrorAction Stop
break
}
catch {
Write-Output “Missing/Invalid Credentials”
Write-Output “Please ensure you AD account is not locked”
Write-Host “”;
Write-Output “Enter Credentials again? [Y/N]”
if ((Read-Host) -ne “Y”) { break }}
}
Any help is appreciated!