Jump to content

Powershell - Get-ADUser Home Directory Server


Recommended Posts

Posted

Hi there

 

I'm creating a tool to change quotas via powershell however we many servers. I would like to be able to type username and it automatically set the server to connect to inorder to change the quota.

 

i was planning to use this line, is there a better way or is it possible to split the full path and return just the servername?

Get-AdUser -filter {SamAccountName -eq $Input} -properties * | Select-Object -ExpandProperty HomeDirectory

 

Thanks

Posted

Paths are as follows.

So would like it to split path up to \ after server name if that makes sense.

 

\\Server-01\Documents\User\Documents

\\ServerB-01\Documents\User\Documents

Posted

So this will get you the server name:-

 

$str = '\\Server-01\Documents\User\Documents'

$StrServer = $Str.TrimStart('\\').Split('\')

$StrServer[0]

 

H.

Posted

Now struggling with the next part

 

I'm using

Invoke-Command -ComputerName $StrServer[0] -ScriptBlock{

 

which works perfectly but my script is now passing the username. I've tried setting this at the beginning of the script like this

$global:input = Read-Host "Enter Username"

 

but after Invoke-Command -ComputerName $StrServer[0] -ScriptBlock{

but when i use $input its empty

 

Am i doing something wrong?

 

Thanks

Posted

Think i've got it working using

 

$local = $input

 

Invoke-Command -ComputerName $StrServer[0] -ArgumentList $local -ScriptBlock{

param($local)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...