Interactive Scripts.txt - Notepad

Interactive Scripts

I used the below script to launch an interactive prompt for a group of users. The script obtains information from a user and then appends it to a comma deliminited csv file as a single row. Note, computername and username could also be obtained using get-childitem env:. The trimend method ensures that any space at the tail of the string is removed. The remove method removes a series of characters from a string. The expandproperty parameter in the select-object cmdlet ensures that property headings are not included in output.
$username = get-wmiobject -class win32_computersystem -property username | select-object -expandproperty username | out-string
$username2=$username.trimend()
$username3=$username2.remove(0,15)

$computername = Get-WmiObject -class win32_computersystem | select-object -expandproperty name | out-string

$fullname = Get-ADUser -Identity $username3 -property displayname | Select-Object -expandproperty displayname | out-string

$location = Read-Host "Please enter the desk number in which your desktop or laptop is located"
$rsa = Read-Host "Do you have an RSA token (enter 'yes' or 'no')"
$usb = Read-Host "Do you have a BHP issued USB drive (enter 'yes' or 'no')"

Write-Host "Thankyou, your information has been forwarded to the Service Desk. If you have any queries please contact the Service Desk."

"{0},{1},{2},{3},{4},{5},{6}" -f $computername.TrimEnd(),(get-date),$fullname.trimend(),$username3,$location,$rsa,$usb | add-content -path c:\stuff\new.csv

Back