Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Read-Host and variables

$
0
0

I have a basic script to search our AD for inactive computers. I want a prompt to specify the search base, and so I tried to use Read-Host Like so:

$WKS = 'OU=Workstations,DC=domain,DC=company,DC=com';
$SVR = 'OU=Servers,DC=domain,DC=company,DC=com';
$OU = Read-Host 'Specify search variable ($WKS or $SVR)';

Search-ADAccount -AccountInactive -TimeSpan 180.00:00:00 -ComputersOnly -SearchBase $OU

However, when I do this, the variable contents are not passed on to $OU, it simply adds the search base variable name and so the search errors out (I am guessing because of the single quotes). If I run it except explicitly assign one of the search base variables it does not work. This indicates to me that Read-Host is the issue in here. 

What ca I do to get around this? I am very new to PowerShell, so I am likely missing something obvious.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>