Monday, December 25, 2017

Run powershell script as domain user from non-domain computer

Leave a Comment
Recently I need to run one powershell script which will bring all files in EPM project folder for project documentation audit. Since I worked as consultant and mostly working on my personal laptop  at different client side. So I was struggling to run this powershell script

$folder = "\\SomePRojectserver\pwa\";
$toInclude =("Shared Documents");
$outputFolder="C:\TempOutput\output.csv";
gci -recurse -Path $folder | select parent,name,Directory |? { $_.Directory -match $toInclude }|
Export-Csv $outputFolder -Encoding UTF8

Reason is b/c powershell take my logged in user credentials either run powershell as administrator with elevated prvilages. So trick is to run following command either through cmd, powershell or through run command:

.\runas.exe /netonly /user:domain\username powershell.exe
If You Enjoyed This, Take 5 Seconds To Share It

0 comments: