String is not in correct format C# -
i using code below.
mysitescript = string.format("$mysitehosturl = \"{0}\"; $personalsiteglobaladmindisplayname = \"sharepoint admin\"; $mysite = get-spsite $mysitehosturl; $context = [microsoft.office.server.servercontext]::getcontext($mysite); $upm = new-object microsoft.office.server.userprofiles.userprofilemanager($context); $allprofiles = $upm.getenumerator(); foreach($profile in $allprofiles) { $displayname = $profile.displayname; $accountname = $profile[[microsoft.office.server.userprofiles.propertyconstants]::accountname].value; if($accountname -like \"{1}\") { if($profile.personalsite -eq $null) { $profile.createpersonalsite(); } else { write-host \"personal site exists.\" ; } } else { write-host \"user not found.\"; } } $mysite.dispose()", mysitehosturl, samaccountname);
getting error: the string not in correct format.
what problem?what suggest?
you should use multi-line string literal i.e. verbatim string:
mysitescript = string.format(@"$mysitehosturl ... ... ...$mysite.dispose()", mysitehosturl, samaccountname);
note - can't use backslash escaping double quotes in verbatim string. use quote-escape-sequence (two consecutive double-quote characters). complete sample:
dmysitescript = string.format(@"$mysitehosturl = ""{0}""; $personalsiteglobaladmindisplayname = ""sharepoint admin""; $mysite = get-spsite $mysitehosturl; $context = [microsoft.office.server.servercontext]::getcontext($mysite); $upm = new-object microsoft.office.server.userprofiles.userprofilemanager($context); $allprofiles = $upm.getenumerator(); foreach($profile in $allprofiles) {{$displayname = $profile.displayname; $accountname = $profile[[microsoft.office.server.userprofiles.propertyconstants]::accountname].value; if($accountname -like ""{1}"") {{ if($profile.personalsite -eq $null) {{ $profile.createpersonalsite(); }} else {{ write-host ""personal site exists."" ; }} }} else {{ write-host ""user not found.""; }} }} $mysite.dispose()", mysitehosturl, samaccountname);
Comments
Post a Comment