active directory - Powershell TestPath and GetADuser Issues based off current location -


i'm having issues set of scripts writing create new active directory users. @ point i'm trying test if prospective account name in use, along whether folder same name exists. below example of i'm using:

$usernametocheck = 'ttesterson'  $samtest = $null $samtest = get-aduser -filter {samaccountname -eq $usernametocheck} -server xx-dc.domain.ca  $pathtotest = '\\fileserver\users$\' + $usernametocheck $foldertest = test-path $pathtotest  if( ($samtest -eq $null) -and ($foldertest -eq $false) ) {#set flag here , stuff} 

here's problem, when run script, can't target specific server (the -server parameter) unless i've set current location ad: similarly, can't test-path work unless i'm not set in ad: able explain why happening, , apart setting location , forth between two?

thanks.

(edited change double quotes single quotes on file path)

if don't have explicit drive in path (which don't since it's unc), powershell assume path in current psdrive/psprovider. specify, prefix path filesystem::.

like this:

$pathtotest = 'filesystem::\\fileserver\users$\' + $usernametocheck 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -